seanooi / iOS-WebP

Google's WebP image format decoder and encoder for iOS
http://seanooi.github.io/iOS-WebP/
MIT License
856 stars 138 forks source link

Decoding error #9

Closed pekpon closed 10 years ago

pekpon commented 10 years ago

Hello!

I'm having this error when I'm trying to decode my NSData:

App(568,0x3c88418c) malloc: *** error for object 0x312eac: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

I cant decode my image... :(

seanooi commented 10 years ago

Can you share your code and post the full output log? It would be easier to debug if I can take a look at what you're working with.

pekpon commented 10 years ago

Yes!

Now i'm not getting errors but the image isn't showing. I'm trying to do this. Encode the image from an UIIMage to webP, encode to base64 and send the image to the server. Later im getting the base64, decoding it to NSData, saving the file into the filesystem and trying to show the decoded webP image.

The code:

Encoding

The encoding code is correct because i'm sending webP image to the server and I can read this image from an Android webP decoder

Decoding

NSData *file = [self base64DataFromString: data ];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];

NSString *path = [documentsDirectory stringByAppendingPathComponent:@"photo.webp"];

[file writeToFile:path atomically:YES];

    [UIImage imageFromWebP:path completionBlock:^(UIImage *result) {
        self.imageView.image = result;
    }failureBlock:^(NSError *error) {
        NSLog(@"%@", error.localizedDescription);
    }];

Info

xCode 5
iOS 7
Decoder Version 0.4.0

Do you know what can I do? Thanks!

seanooi commented 10 years ago

Since iOS7, base64 encoding and decoding has been built into Xcode. Give this piece of code a try:

NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:data options:0];
if (base64Data) {
    NSLog(@"Valid Base64");
}
else {
    NSLog(@"Invalid Base64");
}
pekpon commented 10 years ago

No result...the base64 is valid but the image isn't displayed...

seanooi commented 10 years ago

This might be a stupid question, but did you write the base64 data to file?

[base64Data writeToFile:webPPath atomically:YES]
pekpon commented 10 years ago

Yes, the base64 is saved to file. Dont worry! I will use webP in the future ;)