0

i am selecting one image from photo library to display on my image view.

there is a save button to save this image file to app bundle.

however i need to save the same selected image in another device with the same name(images are same).so if the user entering image name in another device manually,there is a chance to occur the spelling mistake with the image name.so it will not save the same name.

i need to avoid this problem. can i get any unique key from the displayed image(it will always same for the image).then i can save the file name of the image as the unique value without giving a option of entering image name to the user.so the another device will also save the same image as unique name which is saved in another app.

can any tell me a good way to do it.just i need to save the same images with same name in different apps without giving a option to enter image name manually(on i pad based).

Vipin
  • 4,718
  • 12
  • 54
  • 81

1 Answers1

1

You can use the hash of the image like MD5 or SHA

For example a question about MD5 hash :

MD5 algorithm in Objective C

EDIT using the code in the previous link :

MyExtensions.h

@interface NSData (MyExtensions)
    - (NSString*)md5;
@end

MyExtensions.m

#import "MyExtensions.h"
#import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access

@implementation NSData (MyExtensions)
- (NSString*)md5
{
    unsigned char result[16];
    CC_MD5( self.bytes, self.length, result ); // This is the md5 call
    return [NSString stringWithFormat:
        @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
        result[0], result[1], result[2], result[3], 
        result[4], result[5], result[6], result[7],
        result[8], result[9], result[10], result[11],
        result[12], result[13], result[14], result[15]
        ];  
}
@end

Now you can call the code like this:

-(NSString *) md5Image:(UIImage *)img {
    return [UIImagePNGRepresentation(img) md5];
}
Community
  • 1
  • 1
martiall
  • 981
  • 6
  • 7