iPhone - 放大图像,保持质量

发布于 2024-09-07 13:37:16 字数 1343 浏览 3 评论 0原文

我正在开发一个应用程序,允许用户从相机胶卷中选择照片或拍照。从图片来看,我需要将尺寸增加到1050x670并保持图像质量。我可以放大图像,但当我通过电子邮件发送时,图像显得非常像素化。

在应用程序中,我将把放大的图像发送到服务器进行额外处理。

任何帮助将不胜感激。这是一些代码:

CGSize newSize = CGSizeMake(1050, 670);

 CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));

    CGImageRef imageRef = [userImageView.image CGImage];

    // Compute the bytes per row of the new image
    size_t bytesPerRow = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef) * newRect.size.width;
    bytesPerRow = 26 * 1050;//(bytesPerRow + 15) & ~15;  

    CGContextRef bitmap = CGBitmapContextCreate(NULL,
    newRect.size.width,
    newRect.size.height,
    8,
    bytesPerRow,
    CGImageGetColorSpace(imageRef),
    kCGImageAlphaNoneSkipLast);

    CGContextSetInterpolationQuality(bitmap, kCGInterpolationHigh);

    // Draw into the context; this scales the image
    CGContextDrawImage(bitmap, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef resizedImageRef = CGBitmapContextCreateImage(bitmap);
    UIImage *resizedImage = [UIImage imageWithCGImage:resizedImageRef];

    // Clean up
    CGContextRelease(bitmap);
    CGImageRelease(resizedImageRef);

 UIImageWriteToSavedPhotosAlbum(resizedImage, nil, nil, nil);

 return resizedImage;

I am working on an application that allows a user to pick a photo from their camera roll or take a picture. From the picture, I need to increase the size to be 1050x670 and keep the quality of the image. I am able to increase the image, but the picture comes out very pixelated when I send it through email.

In the app, I will be sending the enlarged image to a server for additional processing.

Any help would be appreciated. Here is some of code:

CGSize newSize = CGSizeMake(1050, 670);

 CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));

    CGImageRef imageRef = [userImageView.image CGImage];

    // Compute the bytes per row of the new image
    size_t bytesPerRow = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef) * newRect.size.width;
    bytesPerRow = 26 * 1050;//(bytesPerRow + 15) & ~15;  

    CGContextRef bitmap = CGBitmapContextCreate(NULL,
    newRect.size.width,
    newRect.size.height,
    8,
    bytesPerRow,
    CGImageGetColorSpace(imageRef),
    kCGImageAlphaNoneSkipLast);

    CGContextSetInterpolationQuality(bitmap, kCGInterpolationHigh);

    // Draw into the context; this scales the image
    CGContextDrawImage(bitmap, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef resizedImageRef = CGBitmapContextCreateImage(bitmap);
    UIImage *resizedImage = [UIImage imageWithCGImage:resizedImageRef];

    // Clean up
    CGContextRelease(bitmap);
    CGImageRelease(resizedImageRef);

 UIImageWriteToSavedPhotosAlbum(resizedImage, nil, nil, nil);

 return resizedImage;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够 2024-09-14 13:37:16

UIImagePickerController 将返回缩小后的图像。要获取全尺寸图像,您可以使用 ALAssetsLibrary。

http://developer.apple.com/库/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html

The UIImagePickerController will return a downscaled image. To obtain the full size image you can use the ALAssetsLibrary.

http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文