我想在图像上添加轮廓,你有什么想法吗? 注意:我不需要imageview的边框,而不是imageview.layer.borderColor或image.layer.borderWidth;iphone,如何在图像上添加轮廓?
0
A
回答
5
试试这个:
- (UIImage*)imageWithBorderFromImage:(UIImage*)source;
{
CGSize size = [source size];
UIGraphicsBeginImageContext(size);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
[source drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 0.5, 1.0, 1.0);
CGContextStrokeRect(context, rect);
UIImage *testImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return testImg;
}
来源:http://www.icodesnip.com/snippet/objective-c/add-image-border-to-uiimage
1
这可能不是一个非常干净的方式,但可能工作和简单。
//Make a UIView instance with required coords and size
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(...)];
//Set a backgroundColor, that will be the color of your border
view.backgroundColor = [UIColor ...];
// Make a UIImageView instance with the frame just leaving enough
// space around for the border.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(...)];
imageView.image = yourImage;
// Add the imageView to the view.
[view addSubview:imageView];
[imageView release];
// Release view accordingly after adding to some other view.
视图和imageView的大小将使您的图像的边界。 例如。 (0,0,10,10) - >查看帧 (1,1,8,8) - > imageView frame 这将使图像的边界为“1”。
相关问题
- 1. 如何为图像添加轮廓?
- 2. 在ggmap上添加轮廓
- 3. 在图像上搜索轮廓
- 4. 如何在iPhone中为图像绘制轮廓sdk
- 5. 如何添加标准轮廓?
- 6. 如何从轮廓恢复图像?
- 7. 轮廓添加到地图条件
- 8. 如何在python matplotlib中添加线条到轮廓图中?
- 9. 图像的轮廓轴
- 10. CSS - 如何在圆形图像周围添加圆形边框/轮廓?
- 11. 如何生成轮廓图?
- 12. 如何在iPhone上的图像上按像素添加颜色?
- 13. 轮廓opencv:如何消除二进制图像中的小轮廓
- 14. 如何匹配轮廓检测图像上的字母ASCII?
- 15. 获取轮廓图像Linkedin在Rails
- 16. 如何在iPhone上绘制3D模型轮廓? (OpenGL ES)
- 17. 如何在Iphone的UIView中添加边界轮廓。请阅读说明
- 18. 如何获得轮廓的像素点?
- 19. 如何在netlogo中为海龟添加轮廓颜色
- 20. 如何在OpenCV的图像中查找轮廓?
- 21. 如何保存在sRGB色彩图像轮廓
- 22. 轮廓轮廓着色器
- 23. 添加轮廓颜色,点属性
- 24. 的jython JES:添加晕影轮廓
- 25. 动画轮廓图
- 26. 轮廓图OpenCV4Android库
- 27. 如何获得与Facebook图形API轮廓图像
- 28. 使用openCV查找图像轮廓
- 29. python库查找图像轮廓
- 30. DrawString与图像中的轮廓
感谢您的建议,但你添加一个矩形边框,而我需要的是图像的轮廓。例如帽子图像,我需要围绕帽子的轮廓,而不是围绕它的矩形。 – 2011-06-12 09:25:41
你有什么其他建议吗? – 2011-06-12 09:26:35
这种操作可能需要图像处理,请尝试使用http://code.google.com/p/simple-iphone-image-processing/但它似乎不是那么简单 – AmineG 2011-06-12 11:36:56