SHARE
TWEET

Python - PyPNG struct.error

furas Jun 25th, 2018 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import png
  2.  
  3. data = list()
  4.  
  5. for r in range(0, 512): # r - row number
  6.     row = list()
  7.     for c in range(0, 512): # c - column number
  8.         if r == c:
  9.             row.append(0) # OK (black)
  10.         else:
  11.             row.append((256*256)-1) # OK (white) (65535)
  12.            
  13.             #row.append((256*256)) # ERROR - value too big for bitdepth=16
  14.             # struct.error: 'H' format requires 0 <= number <= 65535
  15.            
  16.             #row.append(-1) # ERROR - value too small for bitdepth=16
  17.             # struct.error: argument out of range
  18.            
  19.     data.append(row)
  20.    
  21. out = png.Writer(width=512, height=512, greyscale=True, bitdepth=16)
  22. out.write(open('output.png', 'wb'), data)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top