java - How to get RGBA color value of an image pixel in python -


i'm trying convert java code python:

bufferedimage image; fileinputstream fstream1 = new fileinputstream("image.png") image = imageio.read(fstream1); int max = -40000000; //java rgb returns negative values  (int = 0; < 128; i++) {     (int j = 0; j < 255; j++)     {         color = image.getrgb(j, i); //returns integer ..... 

i tried in python:

from pil import image  image = image.open("image.png").convert("rgba") pixels = image.load()  in range(128):     j in range(255):         color = pixels[j, i] #returns (r, g, b, a); 

the problem i'm getting different values in python.

why java returns negative integer values , how same result in python?

this function should convert colour python format java format:

def convertpixel(c):     x = c[0] << 16 | c[1] << 8 | c[2] | c[3] << 24     if x >= 1<<31:         x -= 1<<32     return x 

note python's format sane - gives exact r, g, b , values directly. it's java has weird format.

you negative values in java because of integer overflow - example 0xffffffff (or 4294967295), pure white, wraps around -1.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -