
我想要的只是从一些计算生成的10×10灰度图像,如果有一种简单的方法来创建一个png或者很棒的东西.
解决方法 一个非常原始的例子,类似于Mats的建议,但这个版本使用外部像素缓冲区(pixelData):const size_t WIDth = 10;const size_t Height = 10;const size_t Area = WIDth * Height;const size_t ComponentsPerPixel = 4; // rgbauint8_t pixelData[Area * ComponentsPerPixel];// fill the pixels with a lovely opaque blue gradIEnt:for (size_t i=0; i < Area; ++i) { const size_t offset = i * ComponentsPerPixel; pixelData[offset] = i; pixelData[offset+1] = i; pixelData[offset+2] = i + i; // enhance blue pixelData[offset+3] = UINT8_MAX; // opaque}// create the bitmap context:const size_t BitsPerComponent = 8;const size_t BytesPerRow=((BitsPerComponent * WIDth) / 8) * ComponentsPerPixel;CGcolorSpaceRef colorSpace = CGcolorSpaceCreateDeviceRGB();CGContextRef gtx = CGBitmapContextCreate(&pixelData[0],WIDth,Height,BitsPerComponent,BytesPerRow,colorSpace,kCGImageAlphaPremultiplIEdLast);// create the image:CGImageRef tocgImage = CGBitmapContextCreateImage(gtx);UIImage * uiimage = [[UIImage alloc] initWithCGImage:tocgImage];NSData * png = UIImagePNGRepresentation(uiimage);// remember to cleanup your resources! :) 总结 以上是内存溢出为你收集整理的iphone – 从RGB数据创建图像?全部内容,希望文章能够帮你解决iphone – 从RGB数据创建图像?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)