Python image conversion help May 30, 2013 04:37PM |
Registered: 10 years ago Posts: 16 |
import Image import StringIO import serial ser = serial.Serial('COM20', 2000000) def send_image(image): pixels = image.load() ser.write('dicls\r\n') # send cmd to accept image time.sleep(1); ser.write(chr(image.size[1])) # send Height info time.sleep(1); ser.write(chr(image.size[0])) # send width info time.sleep(1); for y in xrange(image.size[1]): for x in xrange(image.size[0]): (r, g, b) = pixels[x, y] result = (r) |(g) |(b) ser.write(chr(result))
Re: Python image conversion help May 30, 2013 06:45PM |
Admin Registered: 11 years ago Posts: 351 |
// ****************************************************************************** // load bitmap using binary input, I think this should work // bitmap format: // <height:H><heigh:L><width:H><width:L> // <r><g><b>...... // ****************************************************************************** void IL_bitmap(unsigned char x, signed int y) { int j, height, width; unsigned char c; COLOUR colr; IL_crSus(1); if(I2Cf) height=i2c1_get()*256; else height=getch()*256; // high byte if(I2Cf) height+=i2c1_get(); else height+=getch(); // lowbyte if(I2Cf) width=i2c1_get()*256; else width=getch()*256; // high byte if(I2Cf) width+=i2c1_get(); else width+=getch(); // lowbyte // basic check if(height > MAXy) height=MAXy; if(width > MAXx) width=MAXx; IL_setAddress(x,y); // set position and global while(height--) { for(j=0;j<width;j++) { if(I2Cf) colr.r=i2c1_get(); else colr.r=getch(); if(I2Cf) colr.g=i2c1_get(); else colr.g=getch(); if(I2Cf) colr.b=i2c1_get(); else colr.b=getch(); IL_pix(colr); } IL_setAddress(cPos.x,++cPos.y); } IL_crSus(0); }ignore the I2C stuff; as you can see 4 bytes are expected before the rgb information. The Python line: