iOS: How to get pngs with transparency when read from disk

I am saving png image to disk as NSData (for caching), when read gives Black color in place of transparent pixels. How to fix that??

this what I am using for saving to disk:

-(void)cacheImage:(UIImage *)image forURL:(NSURL *)url {
NSURL *cacheFileURL = [[self asyncableCachesDirectory] URLByAppendingPathComponent:[[url absoluteString] MD5]];

NSData *imageData = nil;

switch ([self imageTypeForJTDynamicImageURL:url]) {
    case AsyncableImageTypeJPEG:
        imageData = UIImageJPEGRepresentation(image, 1);
    case AsyncableImageTypePNG:
        imageData = UIImagePNGRepresentation(image);

NSError *error = nil;

[imageData writeToURL:cacheFileURL options:0 error:&error];


and this is what I am using for reading image:

-(UIImage *)imageFromCacheForURL:(NSURL *)url {
UIImage *image;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *urlHash;
NSURL *cacheFileURL;

image = [self.images objectForKey:[url absoluteString]];

// if we already have the full size image in memory just return it.
if (image) {
    debug(@"---Asyncable returning full size image from memory for url: %@", url);
    return image;

// check disk for full size image
urlHash = [[url absoluteString] MD5];
cacheFileURL = [[self asyncableCachesDirectory] URLByAppendingPathComponent:urlHash];

image = [UIImage imageWithData:[fileManager contentsAtPath:[cacheFileURL path]]];

if (image) {
    [self.images setObject:images forKey:url];
    debug(@"---Asyncable returning full size image from disk for url: %@", url);

    return image;



imageData = UIImagePNGRepresentation(image);

If used in both the cases what happens?

Need Your Help

Make Trello list of cards scroll

html css trello

I am trying to reconstruct a Trello list in an HTML page. I am almost done except for one small problem. This is the code I have:

How do I pass the image object into the onclick function being assigned to it?

javascript html css

Sorry if that question is confusing, I'm self-learning javascript. I'm dynamically generating image thumbnails and I want to be able to enlarge the image when the user clicks on the thumbnails. My...