Iphone 在非视网膜设备上从UIImagePickerController获取640x640 UIImage
我正在从Iphone 在非视网膜设备上从UIImagePickerController获取640x640 UIImage,iphone,ios,objective-c,uiimage,uiimagepickercontroller,Iphone,Ios,Objective C,Uiimage,Uiimagepickercontroller,我正在从UIImagePickerController获取一个经过编辑的图像。在视网膜iOS设备上,返回的图像为640x640,但在非视网膜iOS设备上,返回的图像仅为320x320 如何从非视网膜设备上的控制器获取640x640,而无需手动放大?我需要的大小是恒定的,无论屏幕,因为我上传它 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictio
UIImagePickerController
获取一个经过编辑的图像。在视网膜iOS设备上,返回的图像为640x640,但在非视网膜iOS设备上,返回的图像仅为320x320
如何从非视网膜设备上的控制器获取640x640,而无需手动放大?我需要的大小是恒定的,无论屏幕,因为我上传它
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
//image.size is 320x320 points on both retina and non-retina devices.
//How do I get 640x640 *pixels* for non-retina devices without upscaling?
}
我不确定,但可能没有调整图像大小,这是不可能得到的视网膜和非视网膜图像自动 因此,您需要通过以下代码调整图像的大小:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
img = [self resizeImage:img];
// here you got, img = 640x640 or 320x320 base on you device;
}
调整图像大小的代码
- (UIImage*)resizeImage:(UIImage*)image
{
CGSize newSize = nil;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]
&& [[UIScreen mainScreen] scale] == 2.0) {
// Retina
newSize = CGSizeMake(640, 640); // Here you need to set size as you want;
} else {
// Not Retina
newSize = CGSizeMake(320, 320); // Here you need to set size as you want;
}
UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
我不确定,但可能没有调整图像大小,这是不可能得到的视网膜和非视网膜图像自动 因此,您需要通过以下代码调整图像的大小:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
img = [self resizeImage:img];
// here you got, img = 640x640 or 320x320 base on you device;
}
调整图像大小的代码
- (UIImage*)resizeImage:(UIImage*)image
{
CGSize newSize = nil;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]
&& [[UIScreen mainScreen] scale] == 2.0) {
// Retina
newSize = CGSizeMake(640, 640); // Here you need to set size as you want;
} else {
// Not Retina
newSize = CGSizeMake(320, 320); // Here you need to set size as you want;
}
UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
展示一些代码怎么样?展示一些代码怎么样?这只是将返回的320x320图像放大到640x640,导致质量损失。这可能不是他们问题的答案,但它确实帮助了我解决了相关问题。谢谢,伙计!这只是将320x320图像放大到640x640,导致质量损失。这可能不是他们问题的答案,但它确实帮助我解决了相关问题。谢谢,伙计!