Reply to comment

Distinct identifier for UIImage - iPhone

I was trying to get a specific identifier for an image from an UIImage object. The idea was to get some value to differentiate a picture from another one in a random way. It needed to be random but it needed to be the same value anytime you run it on the same picture.

I wanted to get the same value from a given picture whenever I open it. I wanted my program to determine a certain value of a picture no matter when or where it opens it so that the same output would happen each time for the same image.

I don't want to save the information because I want it to find the same value for the picture even if it's opened on another iPhone.

I thought if I could determine a value from 0-9, my program would act differently with each value. I was thinking if I could get the file size and then do a mod 10 I could get the value I want. But, I couldn’t seem to find a way to find the file size or the numbers that I was finding were the same for similar pictures.

The following is what I ended up going with. The image.image at the beginning is the UIImage value and of course the output is the integer currentPhrase which ends up being 0-9.

CFDataRef m_DataRef;
m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider([image.image
CGImage]));
int length = CFDataGetLength(m_DataRef);
currentPhrase = CFDataGetBytePtr(m_DataRef)[(length/3) + 1]/25;
CFRelease(m_DataRef);

iPhone Development

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options