相关疑难解决方法(0)

UIImage:调整大小,然后裁剪

我一直在this this for for for for for for and and and while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while

我认为,在我的设计的概念阶段提前,从iPhone的相机或库中获取图像,将其缩小到指定高度,使用与Aspect Fill选项相当的功能将是一件小事. UIImageView(完全在代码中),然后裁掉任何不适合传递给CGRect的东西.

从相机或图书馆获取原始图像非常简单.我很惊讶其他两个步骤的难度.

附图显示了我想要实现的目标.有人请你好好握住我的手吗?到目前为止我发现的每个代码示例似乎都会破坏图像,颠倒过来,看起来像废话,画出界限,或者其他方法都不能正常工作.

iphone core-graphics image-processing ios

187
推荐指数
6
解决办法
12万
查看次数

调整从相机中提取的UIimages的大小也会旋转UIimage?

我从相机获取UIimages并将它们分配给UIImageViews进行显示.当我这样做时,相机给我一个1200 x 1600像素的图像,然后我分配给我的应用程序中的UIImageView.在此条件下,图像在图像视图中按预期显示.但是,当我在将其分配给UIImageView之前尝试调整检索到的UIImage时,图像正在按预期调整大小但是在某处(在RESIZING代码中?)我的UIImage正在进行ROTATED ...结果,当我将调整大小的UIImage分配给UIImageView时,图像旋转90度并在宽高比(1200 x 1600像素)不变的情况下显示为拉伸...

我正在使用它来从相机获取UIImage:

- (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{

        myImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        myResizedImg = [self resizeImage:myImg width:400 height:533];
        [myImageView setImage:myResizedImg];

}
Run Code Online (Sandbox Code Playgroud)

我用它来调整它的大小:

-(UIImage *)resizeImage:(UIImage *)anImage width:(int)width height:(int)height
{

    CGImageRef imageRef = [anImage CGImage];

    CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

    if (alphaInfo == kCGImageAlphaNone)
    alphaInfo = kCGImageAlphaNoneSkipLast;


    CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), alphaInfo);

    CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);

    CGImageRef ref = CGBitmapContextCreateImage(bitmap);
    UIImage *result = [UIImage imageWithCGImage:ref];

    CGContextRelease(bitmap);
    CGImageRelease(ref);

    return result;  
} …
Run Code Online (Sandbox Code Playgroud)

iphone uiimageview uiimagepickercontroller uiimage

35
推荐指数
2
解决办法
3万
查看次数

iPhone - CGImageCreateWithImageInRect旋转一些相机胶卷图片

我正在为iPhone设计一个pixelate应用程序.因为使用iPhone 4相机拍摄的照片太大,因此在更新像素化图片时应用程序工作非常慢,我试图先创建图片的图块,然后更新图块而不是孔图片.

在构建图块时,它适用于以横向模式(2592 x 1936 pxl)和低分辨率图片拍摄的相机胶卷照片,但不适用于以纵向模式拍摄的照片(1936 x 2592 pxl).

从原始图像切割切片的代码如下所示:

for (i = 0; i < NrOfTilesPerHeight; i++) {
  for (j = 0; j < NrOfTilesPerWidth; j++) {
    CGRect imageRect = CGRectMake(j*TILE_WIDTH, i*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
    CGImageRef image = CGImageCreateWithImageInRect(aux.CGImage, imageRect);
    UIImage *img = [UIImage imageWithCGImage:image];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是用这些瓷砖创建的图像逆时针旋转到90度角.

非常感谢,Andrei

iphone crop tile uiimage cgimage

8
推荐指数
1
解决办法
5812
查看次数

iPhone:以纵向模式捕获的图像在UIImageview中以横向模式加载

我正在开发一个应用程序,我在纵向模式下捕获图像,然后移动到另一个带有图像数据的类,并在UIScrollView上的UIImageView中显示该图像.

现在,如果我正在使用图像表单库,它工作正常,但如果我必须捕获图像,它将以横向模式显示数据.下面是我的两个类的代码.:

第1类:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSData *imgData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);

    [picker dismissModalViewControllerAnimated:YES];
        image = [[UIImage alloc] initWithData:imgData];

    CGImageRef imgRefCrop = image.CGImage;
            UIImage *photo = [UIImage imageWithCGImage:imgRefCrop];

    PhotoCropperPage *photoCropper = [[PhotoCropperPage alloc] 
                                           initWithPhoto:photo
                                                 delegate:self                                                  
                uiMode:PCPUIModePresentedAsModalViewController
                                          showsInfoButton:YES];

    [photoCropper setMinZoomScale:0.3f];
    [photoCropper setMaxZoomScale:4.0f];
    [self.navigationController pushViewController:photoCropper animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

第2类:

- (void) loadPhoto
{
    if (self.photo == nil) {
        return;
    }

    CGFloat w = self.photo.size.width;
    CGFloat h = self.photo.size.height;

    CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, roundf(w / 2.0f), roundf(h / 2.0f));
    self.scrollView.contentSize = …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiimageview uiimagepickercontroller

4
推荐指数
1
解决办法
6127
查看次数