furas

Python - PyPNG struct.error

Jun 25th, 2018
107
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×