Problems saving images
Problems saving images
- Subject: Problems saving images
- From: James Housley <email@hidden>
- Date: Fri, 18 Mar 2005 17:49:31 -0500
I am having problems saving images with transparency. I have a sample
image that I created in Photoshop Elements with a transparent
background that I have saved to a .gif and .png, and with a white
background as a .jpg. I then load the image and so a simple edit
(resize) in my program and then want to save it as a .gif, .png or
.jpg. Sounds simple enough.
dest GIF JPG PNG
source
GIF BAD BAD GOOD
JPG GOOD GOOD GOOD
PNG BAD BAD GOOD
The problem is the transparent background is converted to blank for the
entries above with "BAD" The image is in a subclass of NSImageView so
I can edit. Below is the important part of saving.
I know that since JPG does not support transparency, the transparent
part needs to be converted to a color. But I don't understand why the
problem with GIF.
if ([nameParts count] >= 2)
{
if ([[nameParts objectAtIndex:[nameParts count]-1]
isEqualToString:@"gif"])
{
fileType = NSGIFFileType;
}
else if ([[nameParts objectAtIndex:[nameParts count]-1]
isEqualToString:@"jpg"])
{
fileType = NSJPEGFileType;
}
else if ([[nameParts objectAtIndex:[nameParts count]-1]
isEqualToString:@"png"])
{
fileType = NSPNGFileType;
}
}
NSBitmapImageRep *theBitmap = nil;
NSArray *reps = [[Image_Required_Image image] representations];
int i;
for (i = 0 ; i < [reps count] ; i++ )
{
NSImageRep *theRep = [reps objectAtIndex:i];
if ([theRep isKindOfClass:[NSBitmapImageRep class]])
{
theBitmap = (NSBitmapImageRep *)theRep;
break;
}
}
if (nil == theBitmap)
{
NSLog(@"Unable to get a representation");
}
else
{
[[theBitmap representationUsingType:fileType properties:nil]
writeToFile:[[NSString stringWithFormat:@"%@/%@", _openPanelPathImage,
filename] stringByExpandingTildeInPath] atomically:YES];
}
Jim
--
/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden http://www.FreeBSD.org The Power to Serve
email@hidden http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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