如何根据RGB值生成UIImage,暂时用不到这些,记录一下。
来源:互联网 发布:特别纳税调整 知乎 编辑:程序博客网 时间:2024/06/14 18:58
http://www.cocoachina.com/bbs/read.php?tid-60270.html
http://stackoverflow.com/questions/845278/overlaying-a-uiimage-with-a-color
如何根据RGB值生成UIImage,暂时用不到这些,记录一下。
1 先定义UIColor *color = [[UIColor alloc] initWithRed:xxx/255.0f green:xxx/255.0f blue:xxx/255.0f alpha:1.0]; //xxx为RGB的值
2 然后[view setBackgroundColor:color];
3 截图
//获取图像
[刚才的的view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
存image就是你要的 了
- (CGContextRef) createARGBBitmapContextFromImage:(CGImageRef) inImage {
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
void * bitmapData;
int bitmapByteCount;
int bitmapBytesPerRow;
// Get image width, height. We'll use the entire image.
size_t pixelsWide = CGImageGetWidth(inImage);
size_t pixelsHigh = CGImageGetHeight(inImage);
// Declare the number of bytes per row. Each pixel in the bitmap in this
// example is represented by 4 bytes; 8 bits each of red, green, blue, and
// alpha.
bitmapBytesPerRow = (pixelsWide * 4);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
// Use the generic RGB color space.
colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace == NULL)
{
fprintf(stderr, "Error allocating color space\n");
return NULL;
}
// Allocate memory for image data. This is the destination in memory
// where any drawing to the bitmap context will be rendered.
bitmapData = malloc( bitmapByteCount );
if (bitmapData == NULL)
{
fprintf (stderr, "Memory not allocated!");
CGColorSpaceRelease( colorSpace );
return NULL;
}
// Create the bitmap context. We want pre-multiplied ARGB, 8-bits
// per component. Regardless of what the source image format is
// (CMYK, Grayscale, and so on) it will be converted over to the format
// specified here by CGBitmapContextCreate.
context = CGBitmapContextCreate (bitmapData,
pixelsWide,
pixelsHigh,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
if (context == NULL)
{
free (bitmapData);
fprintf (stderr, "Context not created!");
}
// Make sure and release colorspace before returning
CGColorSpaceRelease( colorSpace );
return context;
}
然后:
- (id)initWithCGImage:(CGImageRef)imageRef;
http://stackoverflow.com/questions/845278/overlaying-a-uiimage-with-a-color
如何根据RGB值生成UIImage,暂时用不到这些,记录一下。
1 先定义UIColor *color = [[UIColor alloc] initWithRed:xxx/255.0f green:xxx/255.0f blue:xxx/255.0f alpha:1.0]; //xxx为RGB的值
2 然后[view setBackgroundColor:color];
3 截图
//获取图像
[刚才的的view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
存image就是你要的 了
- (CGContextRef) createARGBBitmapContextFromImage:(CGImageRef) inImage {
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
void * bitmapData;
int bitmapByteCount;
int bitmapBytesPerRow;
// Get image width, height. We'll use the entire image.
size_t pixelsWide = CGImageGetWidth(inImage);
size_t pixelsHigh = CGImageGetHeight(inImage);
// Declare the number of bytes per row. Each pixel in the bitmap in this
// example is represented by 4 bytes; 8 bits each of red, green, blue, and
// alpha.
bitmapBytesPerRow = (pixelsWide * 4);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
// Use the generic RGB color space.
colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace == NULL)
{
fprintf(stderr, "Error allocating color space\n");
return NULL;
}
// Allocate memory for image data. This is the destination in memory
// where any drawing to the bitmap context will be rendered.
bitmapData = malloc( bitmapByteCount );
if (bitmapData == NULL)
{
fprintf (stderr, "Memory not allocated!");
CGColorSpaceRelease( colorSpace );
return NULL;
}
// Create the bitmap context. We want pre-multiplied ARGB, 8-bits
// per component. Regardless of what the source image format is
// (CMYK, Grayscale, and so on) it will be converted over to the format
// specified here by CGBitmapContextCreate.
context = CGBitmapContextCreate (bitmapData,
pixelsWide,
pixelsHigh,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
if (context == NULL)
{
free (bitmapData);
fprintf (stderr, "Context not created!");
}
// Make sure and release colorspace before returning
CGColorSpaceRelease( colorSpace );
return context;
}
然后:
- (id)initWithCGImage:(CGImageRef)imageRef;
阅读全文
0 0
- 如何根据RGB值生成UIImage,暂时用不到这些,记录一下。
- iOS 根据颜色值来生成UIImage
- UIImage:使用RGB颜色值来生成图片
- ios从rgb数据生成UIImage
- IOS 由RGB、UIColor生成UIImage
- ios从rgb数据生成UIImage
- 根据存有RGB值的一维数组生成Image
- [iOS代码] 根据文字生成图片UIImage
- iphone UIImage 如何生成缩略图
- rgb原始数据转为uiimage
- 真希望永远用不到这些代码
- 暂时总结一下
- 定义如何根据区域性设置 DateTime 值的格式并显示这些值。
- 定义如何根据区域性设置 DateTime 值的格式并显示这些值
- 知识地图项目中当前暂时搁置,后期需要优化的地方--给自己记录一下
- 如何根据用户名生成注册码
- 利用颜色值来生成UIImage
- 利用颜色值来生成UIImage
- ssh无密登陆localhost
- 逻辑和判断谁是小偷
- 大数据之大数阶乘
- 博弈论之巴什博弈
- struts2+AJAX实现无刷新进行验证
- 如何根据RGB值生成UIImage,暂时用不到这些,记录一下。
- PB 执行存储过程
- activeMQ实例在项目中的运用二【项目实战系列】
- 查出的表格数据,每一行的特殊处理
- 创建自己的Pod库并上传到CocoaPod上
- Maven_Spring 实例
- android控件之surfaceview
- bootstrap File Input 多文件上传插件使用记录(二)删除原文件
- NLPIR(ICTCLAS 2013)分词工具Python封装