Re: Getting the pixels from an NSImage
Re: Getting the pixels from an NSImage
- Subject: Re: Getting the pixels from an NSImage
- From: Gerard Iglesias <email@hidden>
- Date: Sat, 19 Feb 2005 00:28:38 +0100
On 18 févr. 05, at 22:12, Sean McBride wrote:
Hi all,
My app needs to get the pixels from an NSImage (so I can manipulate them
'by hand'). My understanding is that NSBitmapImageRep's bitmapData: will
do this. It works generally, but sometimes NSImage's representations:
gives me a NSCachedImageRep instead (and there are no other
representations). (I'm only dealing with jpegs here, no vector format files.)
How can I reliably get an NSBitmapImageRep from an NSImage?
It depends on the way you get the NSImage object, maybe to get the bitmap it would be easier to make a NSBitmaptImageRep directly from the data of the corresponding file.
for example this code work with any supported NSBitmapImageRep file type :
- ()sender
{
NSOpenPanel * openPanel = [NSOpenPanel openPanel];
(([openPanel runModalForTypes:[NSBitmapImageRep imageFileTypes]] == NSOKButton)){
NSString * theFileName = [[openPanel filenames] objectAtIndex:];
NSData * theData = [NSData dataWithContentsOfFile:theFileName];
NSBitmapImageRep * theRep = [NSBitmapImageRep imageRepWithData:theData];
(theRep){
NSImage * theImage = [[[NSImage alloc] init] autorelease];
[theImage addRepresentation:theRep];
[imageView setImage:theImage];
}
}
}
the imageView is an NSImageView to check that it's work
Or this very dummy line does work with any image :
[[NSBitmapImageRep imageRepWithData:[anImage TIFFRepresentation]] retain]
And look at the method ,:
<x-tad-bigger>imageRepsWithData</x-tad-bigger>, that return a list of image contained in the file.
I didn't check that you get the bitmapPlane, but id does work I think....
regards
Gerard
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden