Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to save as .png, but I get .jpg
    text
    copied!<p>I am saving to the photo Album, I want the file to be a .png but it saves as a .jpeg? Is it even possible to save a .png to the Photo Album?</p> <p>here is my code:</p> <pre><code>CGContextRef MyCreateBitmapContext (int pixelsWide,int pixelsHigh) { CGContextRef context = NULL; //CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); //colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { fprintf (stderr, "Memory not allocated!"); return NULL; } context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8,//bits per component bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (context== NULL) { free (bitmapData); fprintf (stderr, "Context not created!"); return NULL; } CGColorSpaceRelease( colorSpace ); return context; } </code></pre> <p>and:</p> <pre><code>- (IBAction)save:(id)sender{ myBitmapContext = MyCreateBitmapContext (400, 300); // ********** Your drawing code here ********** CGContextSetRGBFillColor (myBitmapContext, 1, 0, 0, 1); CGContextFillRect (myBitmapContext, CGRectMake (0, 0, 400, 300 )); // ********** Your drawing code here ********** CGImageRef imageRef = CGBitmapContextCreateImage(myBitmapContext); UIImage * image = [[UIImage alloc] initWithCGImage:imageRef]; //NSData* imdata = UIImagePNGRepresentation ( image );// get PNG representation //UIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); // save to photo album [image release]; CGImageRelease(imageRef); CGContextRelease(myBitmapContext); } </code></pre> <p>many thanks for any ideas</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload