共有一个父类uiview,在uiview里面有一个imageview,和一个子uiview,imageview用来进行初始化图片,一个uiview在imageview上面进行剪切,有一些touche事件来使的uiview在imageview范围内,并且设置最小值,最大值为整个imageview的范围,并且实现旋转角度剪切效果。如果旋转,如何保持uiview的范围在imageview上~ 只截取在uiview上的图片, 不管是否旋转角度~,我是初学者~求思路~ |
|
前阵子为一个帖子做了个类似的,没有加旋转??
有用就翻翻 |
|
40分 |
找不到的话,告诉我邮箱
|
ljp8817@gmail.com
|
|
免得别人说我不地道,贴核心代码
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; CGRect rect = CGRectMake(currentPoint.x+3, currentPoint.y+3, v.bounds.size.width, v.bounds.size.height); v.frame = rect; v.image = [self createRectImage:pubImg rect:rect]; [v setNeedsDisplay]; } -(UIImage*) createRectImage:(UIImage*)image rect:(CGRect) rect { // the size of CGContextRef CGImageRef imageRef=CGImageCreateWithImageInRect([image CGImage],rect); UIImage* elementImage=[UIImage imageWithCGImage:imageRef]; return elementImage; } |
|
我昨天做好了,可以剪切图片,但是旋转的话,图片切不准~求高手解答~
对图片进行处理(得到某张图片的一部分)可一用以下代码:? UIImage *image = [UIImage imageNamed:filename];? CGImageRef imageRef = image.CGImage;? CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);? CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);? UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect];? 把当前的视图作为照片保存到相册中去:? #import <QuartzCore/QuartzCore.h>? UIGraphicsBeginImageContext(currentView.bounds.size);???? //currentView 当前的view? [currentView.layer renderInContext:UIGraphicsGetCurrentContext()];? UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();? UIGraphicsEndImageContext();? UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);? 使UIimageView的图像旋转:? float rotateAngle = M_PI;? CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);? imageView.transform = transform;? |
|
有没有方法,使得一个uiview和一个uiimageview重合的区域进行处理。。。。
|