Я работаю над приложением, которое позволяет пользователю выбрать фотографию из своего фотоаппарата или сделать снимок. Из картинки мне нужно увеличить размер до 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;