Re: [OT]Dynamic Image Generation
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 29, 2003
- 392 views
On Thu, 29 May 2003 09:36:47 +0000, Robert Szalay <robsz1 at hotpop.com> wrote: >Hello list. > >I am looking for a program. I need to be able to pass it a string and=20 >it make the string into an image(bmp, jpeg, or gif). > > >I am on windows. > >Any suggestions? > Hi Robert, Not quite sure why you think this is off topic... Anyway, this is all you need do for a bmp: include win32lib.ew constant bm=3Dcreate(Pixmap,"",0,0,0,100,30,0) setPenColor(bm,LightGray) drawRectangle(bm, 1, 0,0, 100, 30) setPenColor(bm,Black) setFont(bm, "Arial", 10, 0) setPenPos(bm, 5, 5) wPuts(bm,"Hello World") If you want to save it to file,=20 heres an old [and slow] David Cuny routine: function getRGB( atom a ) -- convert rgb atom to {rgb} return {and_bits(a,#FF), and_bits(a,#FF00)/#100, and_bits(a,#FF0000)/#10000} end function procedure savePixmapToFile( atom pixmap, sequence fName ) --save pixmap to bitmap file integer at, cx, cy sequence size, pal, bmp, pix -- get extent size =3D getExtent( pixmap ) cx =3D size[1] cy =3D size[2] -- empty bitmap and pal bmp =3D repeat( repeat( 0, cx ), cy ) pal =3D {} for y =3D 1 to cy do for x =3D 1 to cx do -- get a pixel pix =3D getRGB( getPixel( pixmap, x, y ) ) -- in the pal? at =3D find( pix, pal ) if at =3D 0 then -- add to pal pal =3D append( pal, pix ) -- get index at =3D length( pal ) end if -- add to bitmap bmp[y][x] =3D at - 1 end for end for -- make at least 16 colors if length( pal ) < 16 then pal &=3D repeat( {0,0,0}, 16-length(pal) ) end if if save_bitmap( {pal,bmp}, fName ) then warnErr( "Unable to save bitmap " & fName ) end if end procedure In the above code call that with savePixmapToFile(bm,"test.bmp") Pete