Pixmap manipulation and code optimisation
BlitzMax Forums/BlitzMax Beginners Area/Pixmap manipulation and code optimisation
| ||
Hi! I use this piece of code to read all image files in a loop. Resize them down to ICONSIZE and create a iconstrip out of them all. 1. Can I manipulate the shrinked pixmap? I'd like to add a black 1 pixel border to the resized images. before I paste them to the imagestip itself. In BP I simply would use the imagebuffer and draw the black border lines onto it. But with bmx and pixmaps I have no idea. 2. Can this whole process be done faster. I don't need the globalpixmap or the other media in memory for later use. The Iconsize is I use currently is 96 x 96 pixels. The whole strip is 12.576+ x 96 pixels large! Global Fullpixmap:TPixmap=CreatePixmap(((MAXFOLGEN)*ICONSIZE),ICONSIZE,PF_BGR888,1) For Local i=0 To MAXFOLGEN-1 Local tmppixmap:TPixMap=LoadPixmap("media/"+i+".jpg") ' Load media files fullpixmap.paste(ResizePixmap(tmppixmap,ICONSIZE,ICONSIZE),i*ICONSIZE,0) 'and paste them to the global pixmap Next ' Output SavePixmapPNG(fullpixmap, "stripimg.png",9 ) |
| ||
Looks pretty good to me. You can use Readpixel and Writepixel to draw to Pixmaps. |
| ||
Thanks for the hint! I think using "Drawimagerect" would be faster than using paste? |
| ||
You can have a pixmap that is 2 pixels wider and taller than the source data, clear it to black, then paste your pixmaps to 1,1. Then paste that whole pixmap into your strip. |
| ||
How do I clear a pixmap to full black please? setcolor 0,0,0 cls pixmap :) |
| ||
full black? with createpixmap Pixmap:TPixmap=CreatePixmap(Pixmap.Width,Pixmap.Height,Pixmap.Format) |
| ||
and what you want to do?, add 1 pixel extra to the image? or cut 1 pixel? anyway you can use pixmapwindow resize image to 96x96 and cut 1 pixel of image For Local i=0 Until MAXFOLGEN Local tmppixmap:TPixMap=LoadPixmap("media/"+i+".jpg") ' Load media files fullpixmap.paste(PixmapWindow(ResizePixmap(tmppixmap,ICONSIZE,ICONSIZE),1,1,ICONSIZE-2,ICONSIZE-2),1+i*ICONSIZE,1) 'and paste them to the global pixmap Next ' Output SavePixmapPNG(fullpixmap, "stripimg.png",9 ) resize image to 94x94 (1 pixel border) fullpixmap.paste(ResizePixmap(tmppixmap,ICONSIZE-2,ICONSIZE-2),1+i*ICONSIZE,1) |
| ||
Thanks. What is a 'virtual' window inside the pixmap? |
| ||
Normally a pixmap has its own memory buffer to store pixels, attached to the header information that describes the width, height, pitch etc. An alternative is that you have this header information pointing to some other pre-existing block of memory, that is associated with some other pixmap. So the two pixmap headers sort of share the same pixmap pixels. Then using that `window within a pixmap`, you can just deal with what is within that window, like a clipped window, and ignore what's outside of it. |
| ||
Ah, ok. Thank you again. They should put such text into the docs... :) |