我有关于不规则形状的问题。我搜查了很多,但没有什么对我有用。我有许多不规则形状的框架,每个框架又被分成多个子区域。我想在照片库的每个子区域中放入图片。但我无法获得每个子区域的位置,并且因为形状也不规则,所以再次成为另一个适合该区域图像的问题。谁能帮我 !!这是该框架的一个例子。 如何在不规则形状的框架中适合图像
回答
你永远不会有不规则形状的框架。框架将始终保持原状。 您可以通过检测透明区域来完成。
我想我误解了你的问题:|你能解释一下确切的情况吗? – DivineDesert
认为有圆圈,它分为四个部分。我必须在该区域添加图像。圆的边界和划分为零件的线将成为框架的一部分,框架的所有其他部分将是透明的手段,我必须在该部分适合imageview。 –
你想通过圆弧裁剪的各种图像?例如,这里是一个具有四个图像(只是随机图像我从搜索得到了狗上http://images.google.com)的屏幕快照:
这里是由圆裁剪相同的四个图像(或者更准确中,四个图像分别由相同的圆路径裁剪):
下面是确实的代码
- (UIImage *)cropImage:(UIImage *)image locatedAt:(CGRect)imageFrame byCircleAt:(CGPoint)center withRadius:(float)radius
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, imageFrame.size.width, imageFrame.size.height, 8, 4 * imageFrame.size.width, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextBeginPath(context);
CGRect ellipseFrame = CGRectMake(center.x - imageFrame.origin.x - radius, imageFrame.size.height - (center.y - imageFrame.origin.y - radius) - radius * 2.0, radius * 2.0, radius * 2.0);
CGContextAddEllipseInRect(context, ellipseFrame);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, imageFrame.size.width, imageFrame.size.height), image.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
CGImageRelease(imageMasked);
return newImage;
}
- (void)addSingleCroppedImage:(UIImage *)image at:(CGRect)imageFrame byCircleAt:(CGPoint)center withRadius:(float)radius
{
UIImage *newImage = [self cropImage:image locatedAt:imageFrame byCircleAt:center withRadius:radius];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageFrame];
imageView.image = newImage;
[self.view addSubview:imageView];
}
- (void)addCroppedImages
{
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
CGPoint center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.width/2.0);
float radius = 150.0;
UIImage *dog1 = [UIImage imageWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"imgres-1.jpg"]];
UIImage *dog2 = [UIImage imageWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"imgres-2.jpg"]];
UIImage *dog3 = [UIImage imageWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"imgres-3.jpg"]];
UIImage *dog4 = [UIImage imageWithContentsOfFile:[bundlePath stringByAppendingPathComponent:@"imgres-4.jpg"]];
CGRect frame;
UIImage *currentImage;
// upper left
currentImage = dog1;
frame = CGRectMake(center.x - currentImage.size.width, center.y - currentImage.size.height, currentImage.size.width, currentImage.size.height);
[self addSingleCroppedImage:currentImage at:frame byCircleAt:center withRadius:radius];
// upper right
currentImage = dog2;
frame = CGRectMake(center.x, center.y - currentImage.size.height, currentImage.size.width, currentImage.size.height);
[self addSingleCroppedImage:currentImage at:frame byCircleAt:center withRadius:radius];
// lower left
currentImage = dog3;
frame = CGRectMake(center.x - currentImage.size.width, center.y, currentImage.size.width, currentImage.size.height);
[self addSingleCroppedImage:currentImage at:frame byCircleAt:center withRadius:radius];
// lower right
currentImage = dog4;
frame = CGRectMake(center.x, center.y, currentImage.size.width, currentImage.size.height);
[self addSingleCroppedImage:currentImage at:frame byCircleAt:center withRadius:radius];
}
雅亲爱的你明白了我的观点。但是你在四个图像视图中设置图像后裁剪图像,但我的问题是我有一个像你的第二个图像的框架,我必须在这个框架中设置图像。意思是我的框架已经定义好了,我必须在该特定区域中触摸设置图像。 –
所以你只需要一个图像,你想用圆圈裁剪?或者你有一个用于圆形“框架”的现有图形元素(这是一个糟糕的词,因为它意味着在UIView世界中非常不同的东西!),你需要把你的图像放入?不知道我是否理解你所指的这个“框架”是什么样的东西。 – Rob
- 1. 以不规则形状裁剪图像
- 2. 与图像碰撞(不规则形状)
- 3. 如何使图像适合Android的圆形框架
- 4. 拉伸形状适合框架?
- 5. 图像不适合UIImageView的框架
- 6. Busniess规则如何适合实体框架生成的Entites?
- 7. 不规则形状
- 8. 将矩形图像变形为不规则形状
- 9. 创建一个不规则形状的框架
- 10. 邻近的不规则形状的图像
- 11. Android onTouch不规则形状
- 12. 目标c:相邻放置不规则形状的图像
- 13. 不规则的矩形形状
- 14. PDF中的不规则形状区域
- 15. Android布局中的不规则形状
- 16. CSS中的不规则形状
- 17. 算法以适应矩形最少到不规则形状
- 18. 如何在cocos2d中跟踪具有不规则形状图像边界的图像的交集?
- 19. 如何在C++中创建不规则形状的按钮?
- 20. CSS规则并不适用于图像
- 21. 如何将图像从不规则矩形更改为矩形?
- 22. 当新形状在加工时形成不规则形状
- 23. Matlab适合图形图像
- 24. 如何从iphone中的uiimageview中获取不规则形状内的像素?
- 25. 如何在OpenGL中绘制2D不规则曲线形状
- 26. 如何在Android布局中布局不规则形状
- 27. 将不规则形状拟合成圆形
- 28. 如何制作不规则形状精灵的矩形?
- 29. 如何在Web语言中以不规则的多边形形状缩放图像。
- 30. 如何使用物镜将图像切割成不规则形状c
你可以给我们一些关于形状的性质,它是如何产生的,“子区域”的性质等信息? – Rob
认为有圆圈,它分为四个部分。我必须在该区域添加图像。圆的边界和划分为零件的线将成为框架的一部分,框架的所有其他部分将是透明的手段,我必须在该部分适合imageview。 –