32bit float array to PNG thanks to NSBitmapImageRep problem
32bit float array to PNG thanks to NSBitmapImageRep problem
- Subject: 32bit float array to PNG thanks to NSBitmapImageRep problem
- From: Pierre-Yves Aquilanti <email@hidden>
- Date: Tue, 8 Jun 2010 10:38:39 +0200
Hello,
i'm trying to convert a float array to a greyscale PNG with a
NSBitmapImageRep but i doesn't work and all i get is a blank png (just
white).
To test the feasibility of my idea i created a float array of size 55*77
with half filled with 1500. and the other half filled with 3000. Theorically
i should obtain a PNG that looks like the picture in the following link :
http://www.hostingpics.net/viewer.php?id=315752capture.png
Here is the source code that i use :
/************************************ Code begin
******************************************/
//load the floating point array
NSData * binaryData=[NSData dataWithContentsOfFile:binaryPath]; //binary is
just a 32bits array full of 1500. and 3000. as described previously
//get a pointer
datapointer = (unsigned char *) [binaryData bytes];
//convert the array into a NSBitmapImageRep
NSBitmapImageRep * bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:&datapointer pixelsWide:sx pixelsHigh:sz
bitsPerSample:32
samplesPerPixel:1 hasAlpha:NO isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace
bitmapFormat:NSFloatingPointSamplesBitmapFormat
bytesPerRow:4*sx
bitsPerPixel:32];
//save it to png format
NSData * tow = [bitmap representationUsingType:NSPNGFileType
properties:nil];
[tow writeToFile:@"/Users/Perif/Desktop/img.png" atomically:NO];
/************************************Code
End******************************************/
My questions are : Is this the proper way to do what i want (convert a
32bits float array to a greyscale PNG) ? What is my error ?
Thanks a lot for your help.
Perif
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden