Converting RGB data into a bitmap in Objective-C++ Cocoa -


I have a buffer of RGB unsigned char which I would like to convert to a bitmap file, does anyone know that how?

R [(0,0)], g [(0,0)], b [(0,0)], r [(0, 1)], g [( 0,1)], b [(0,1)], r [(0,2)], g [(0,2)], b [[0,2]]. ....

Each data unit has a value of 0 to 255. Anyone have any idea how can I do this conversion?

You can use CGBitmapContextCreate to create a bitmap context with your raw data. Then you can create a CGImageRef from the bitmap context and save it. Unfortunately, CGBITMap CONTACT content is a small pickup about the format of data. It does not support 24-bit RGB data Initially, for loop RGB data in RGB, swizzles with zero alpha values ​​at the end. You must include and link with the application services framework.

  four * rgba = (four *) malloc (width * height * 4); (Int i = 0; i & lt; width * height; ++ i) {RGBA [4 * i] = mayebfur [3 * i]; RGBA [4 * I + 1] = Myobfar [3 * I + 1]; RGBA [4 * I + 2] = Myobfar [3 * I + 2]; RGBA [4 * i + 3] = 0; } CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); CGContextRef bitmapContext = CGBitmapContextCreate (RGBA, width, height, 8, // bitspiper 4 * width, // byte color, kCGImageAlphaNoneSkipLast); CFRelease (colorspace); CGImageRef cgImage = CGBitmapContextCreateImage (BitmapConttex); Seafrrrrrr URL = cflcreativefile systempath (kcfaloceter default, CFRTR ("image page"), KCFRPPOSISXAPPS style, false); CFStringRef Type = KUTTypePNG; // or kUTTypeBMP if you like CGImageDestinationRef dest = CGImageDestinationCreateWithURL (url, type, 1, 0); CGImageDestinationAddImage (destination, cgImage, 0); CFRelease (cgImage); CFRelease (bitmapContext); CGImageDestinationFinalize (Destination); Free (RGBA);  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -