×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    8

    Problems with rgb data from png image- strange hex number form '\x00'

    Hello everyone!

    I am trying to get the rgb values of each pixel from a png image i took with the phone camera. The code i am using is:

    f= open("E:\\Images\\minic1.png", "rb")
    f.seek(8+8+13+4)
    chunk = []
    while 1:
    n = struct.unpack(">L", f.read(4))[0]
    if n==0: break #'IEND' chunk
    f.read(4)
    chunk.append(f.read(n))
    f.read(4)
    f.close()
    data = zlib.decompress("".join(chunk))

    unfortunately, this leaves me with the array 'data', whose elements are meant to be hex number values but come out in the form '\x00', which confuses python and it won't let me manipulate it as a string/convert it to a decimal number. It can compare this type of number to each other correctly( i.e. it could correctly deduce that, for example, 'x\00'>'\xff'), but that's about it. I tried changing the '\' with a '0' but it won't let me. How do i overcome this?

    Thank you in advance,

    N

  2. #2
    Registered User
    Join Date
    Apr 2009
    Posts
    166

    Re: Problems with rgb data from png image- strange hex number form '\x00'

    i know there is a sample script on how to read the data from a grayscale
    it uses almost the same code that you do
    i ll post it in ~ 16 hours if i find it :P

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    166

    Re: Problems with rgb data from png image- strange hex number form '\x00'

    try this if you have already data:

    new_data = []
    for i in range(len(data)):
    new_data.append(ord(data[i]))

Similar Threads

  1. fit .png image in MIDlet form
    By siddeep in forum General Messaging
    Replies: 1
    Last Post: 2010-03-22, 21:07
  2. Replies: 6
    Last Post: 2010-02-10, 16:15
  3. puting a png image with other image data in the file
    By TacB0sS in forum Mobile Java General
    Replies: 17
    Last Post: 2009-12-07, 11:03
  4. How to get RGB values from PNG Data byte[]
    By allypone in forum Mobile Java Media (Graphics & Sounds)
    Replies: 11
    Last Post: 2009-09-09, 17:37
  5. PNG rgb data
    By MTi in forum Symbian
    Replies: 2
    Last Post: 2007-02-23, 12:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×