[英]iOS - Objective-C: Image manipulation and processing
I am developing an iOS application (Objective C) in which I needed to deal with image manipulation. 我正在开发一个iOS应用程序(Objective C) ,我需要处理图像处理。
Functions to do in module of application are, 应用模块中的功能是,
Take any image (parent-image) that you want to edit. 拍摄要编辑的任何图像(父图像)。 Then put other images like similes, emojies, sticker into that image.
然后将其他图像如similes,emojies,贴纸放入该图像中。 The sub-images should be Scalable, Rotatable, Draggable within parent image bounds.
子图像应在父图像边界内可伸缩,可旋转,可拖动。
I succeeded to manage sub-images scale, rotate, drag effects. 我成功地管理了子图像缩放,旋转,拖动效果。
But the problem is, during the scaling, rotating, dragging sub-image, the portion of image that lies outside the parent image should become blur or lower its alpha value than the portion of image inside the parent-image. 但问题是,在缩放,旋转,拖动子图像期间,位于父图像外部的图像部分应该变得模糊或者比父图像内部的图像部分更低。
I've attached the reference screenshot of the output that I am looking for. 我附上了我正在寻找的输出的参考屏幕截图。
This is the reference image of the output, I am looking for 这是输出的参考图像,我正在寻找
Edit: Here is the code snippet. 编辑:这是代码段。
UIImageView* randomView = [[UIImageView alloc] initWithFrame:CGRectMake(130, 200, 100, 100)];
randomView.image = image; //image coming from gallery
randomView.userInteractionEnabled = YES;
randomView.alpha = 0.8;
imageView.backgroundColor = [UIColor clearColor];
imageView.opaque = NO;
randomView.backgroundColor = [UIColor clearColor];
randomView.opaque = NO;
[self addPanGesture:randomView];
[self addPinchGesture:randomView];
[self addRotateGesture:randomView];
[imageView addSubview:randomView];
I think this demo you are asking for... Check this demo : 我想你要求的这个演示...查看这个演示:
http://sugartin.info/2011/10/21/mask-and-crop-of-an-image/ http://sugartin.info/2011/10/21/mask-and-crop-of-an-image/
First crop the image by another image shape & then Replace the following Function in the demo to get your requirement like this.... 首先通过另一个图像形状裁剪图像,然后在演示中替换以下函数以获得您的要求....
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.image_view.image=[self maskImage:img withMask:[UIImage imageNamed:@"frame.png"]];
UIImageView *viewImg=[[UIImageView alloc]initWithFrame:self.image_view.frame];
viewImg.image=img;
viewImg.alpha=0.4;
[self.view addSubview:viewImg];
[self.view sendSubviewToBack:viewImg];
}
This demo gives me this type of result... 这个演示给了我这种类型的结果......
In case, if you want only masking image function with another Image, Here it is..
万一,如果你只想掩盖图像功能与另一个图像, 这里是..
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];
}
Hope this would help.. Let me know if that works or not...Thanks.. :) 希望这会有所帮助..让我知道是否有效...谢谢.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.