相关疑难解决方法(0)

调整从相机中提取的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万
查看次数