简体   繁体   English

裁剪并调整从图库或照相机中选择的图像的大小

[英]crop and resize image that is selected from gallery or camera

I am new to iOS development and I really need some help in a task. 我是iOS开发的新手,在工作中确实需要一些帮助。 I need to know how does the cropping and re-sizing image is done in Objective-C . 我需要知道如何在Objective-C完成croppingre-sizing image For registration I need to select a profile image and then I want to crop and resize it, But I am unaware how to do it. 要注册,我需要选择一个个人资料图片,然后我要对其进行裁剪和调整大小,但是我不知道该怎么做。 I have seen many source codes in Github and at SO but none of them seems to help out. 我在GithubSO看到了许多源代码,但似乎没有一个能帮上忙。 Can anyone guide me how does the cropping image work in iOS? 谁能指导我如何在iOS中裁剪图像?

Here is the screenshot of my page I'm working on- 这是我正在处理的页面的屏幕截图-

屏幕截图

Why you are not using standard UIImagePickerController? 为什么不使用标准的UIImagePickerController? If you set imagePicker.allowsEditing = YES; 如果设置imagePicker.allowsEditing = YES; and then in imagePickerController:didFinishPickingMediaWithInfo delegate method get 然后在imagePickerController:didFinishPickingMediaWithInfo委托方法中获取

UIImage *newImage = info[UIImagePickerControllerEditedImage];

you'll get the image cropped by user. 您将按用户裁剪图像。

you can use this function Pass an image and size in it and get image in return. 您可以使用此函数在其中传递图像和尺寸并获取图像。

+ (UIImage*)imageWithImage:(UIImage*)image 
               scaledToSize:(CGSize)newSize;

{

   UIGraphicsBeginImageContext( newSize );

   [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

   UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

   UIGraphicsEndImageContext();

   return newImage;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM