Re: Convert PICT to NSImage
Re: Convert PICT to NSImage
- Subject: Re: Convert PICT to NSImage
- From: Greg Titus <email@hidden>
- Date: Mon, 27 Jun 2005 12:11:26 -0700
On Jun 27, 2005, at 10:38 AM, Ian was here wrote:
I'm getting PICT data from an apple event. There is an
application called Equation Editor that allows for
creating math equations and formulas. When quitting,
Equation Editor converts the equations into a single
PICT file and sends it as an apple event. My
application gets this PICT data. I confirmed that I'm
getting data, and this works fine with an OS 9 version
of my application. So I know I'm getting a PICT file.
The following code seems to work OK:
[NSData dataWithBytes:Pict length:GetHandleSize(
(Handle)Pict )]
It's the NSPICTImageRep imageRepWithData: that is
failing.
Also, dragging an equation onto my text view from
Equation Editor works fine.
Hey Ian,
The problem is - I bet - that the in-memory format of a PICT image is
different from the on-disk format of a PICT image. Probably
NSPICTImageRep is expecting the latter, and you are giving it the
former. When a PICT is saved, it has a 512 byte header stuck on the
front for historical reasons, whose content is completely ignored. Try:
NSMutableData *result = [NSMutableData data];
NSData *data = [NSData dataWithBytes:Pict
length:GetHandleSize((Handle)Pict )];
[result setLength:512]; // blank 512 byte header for PICT file
saved to filesystem
[result appendData:data];
And then feed the "result" data into NSPICTImageRep.
Hope this helps,
- Greg
_______________________________________________
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