How get the image Parse in Byte?

Discussion in 'iOS Programming' started by muzammil, Jan 25, 2010.

  1. muzammil macrumors newbie

    Joined:
    Oct 4, 2009
    Location:
    New Delhi
    #1
    Hi All !

    I am trying to create an UIImage from a byte array which i get from a webservice.It comes embedded in a XML.I can parse the XML and get the byte array as a string.Then I convert the byte array (which is in NSString) to NSData. This is the code for that:-

    Code:
    NSString *Image_String = currentElementValue;
    
    NSData *My_Data = [Image_String dataUsingEncoding:NSUTF8StringEncoding]
    
    UIImage *Image_From_XML = [[UIImage alloc] initWithData: My_Data];
    ///////////////////////// It's not working :(

    I got my "Image_String" as "/9j/DAPEIROEOPJVCIUMKJDFKDJFEEREMERELREMFDO......."
    And in "My_Data" 12324 bytes.. and nothing in "Image_From_XML" ( 0X0 image ) :(
    Can anyone have idea about this ???
    How can i load my image which is Parse by xml (in binary format).

    Thnax in Advance.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    What format is the data? Is it PNG, JPG, etc., or the raw RGBA/etc bytes? If you don't know, I suggest you find out ;)
     
  3. muzammil thread starter macrumors newbie

    Joined:
    Oct 4, 2009
    Location:
    New Delhi
    #3
    @Above: Thanx for the reply

    Actually i am new in Objective C. So can you please show me some code that how can i find this ?
    I think it is in jpg format. Please reply ASAP.
     
  4. Kareny macrumors newbie

    Joined:
    Jun 21, 2010
    #4
    Hi, have you solved the problem? Cause I have the same question and my image is PNG. How can I convert to byte array?
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    In order for binary data like an image to be embedded in xml it has to be encoded somehow. I guess something like base64 is used (I really don't know.) In order to make it back into an image the code needs to decode the base64, or whatever it is. That is the step that's missing from the OP's code.
     
  6. Kareny macrumors newbie

    Joined:
    Jun 21, 2010
    #6
    Thanks very much ~~
     

Share This Page