How you lot exporting your images / pixmaps to a paint program?. I really dont wish to have to code my own :/
Saving images / pixmaps
BlitzMax Forums/BlitzMax Programming/Saving images / pixmaps Hi Shagwana :)
i have find this :) i hope help you :)
i have find this :) i hope help you :)
imageload$ = "c:/filou\mappemonde.bmp" imagesave$ = "c:/filou\test.bmp" Graphics 640, 480, 0 AutoMidHandle True img = LoadImage(imageload$) DrawImage img, 319, 239 Flip WaitKey() SaveImage img, imagesave$ End ' BMP save stuff blatantly stolen from Simon Armstrong's BPaint example. Function SaveImage(image:TImage,filename$) Local stream:TStream stream=WriteStream(filename) If stream WriteBMP stream,image.masks[0] CloseStream stream EndIf End Function Function WriteBMP( stream:TStream,pixmap:TPixmap ) Local buf:Byte[1024] Local hsize,hoffset Local size,width,height Local planes,bits,compression,isize,xpels,ypels,cols,inuse Local w,y width=pixmap.width height=pixmap.height w=width*3 w=(w+3)&$fffc hsize=w*height+54 size=40 hoffset=54 planes=1 bits=24 compression=0 isize=40 xpels=2834 ypels=2834 cols=0 inuse=0 stream=LittleEndianStream( stream ) WriteByte stream,Asc("B") WriteByte stream,Asc("M") WriteInt stream,hsize WriteInt stream,0 WriteInt stream,hoffset WriteInt stream,size WriteInt stream,width WriteInt stream,height WriteShort stream,planes WriteShort stream,bits WriteInt stream,compression WriteInt stream,isize WriteInt stream,xpels WriteInt stream,ypels WriteInt stream,cols WriteInt stream,inuse buf=New Byte[w] For y=height-1 To 0 Step -1 ConvertPixels(pixmap.pixelptr(0,y),pixmap.format,buf,PF_BGR888,width) stream.WriteBytes(buf,w) Next End Function Function CopyImage:TImage( src:TImage,x,y,width,height ) Local image:TImage Local srcpix:TPixmap,destpix:TPixmap Local format,i srcpix=src.masks[0] format=srcpix.format destpix=CreatePixmap(width,height,format) For i=0 Until height CopyPixels srcpix.PixelPtr(x,y+i),destpix.PixelPtr(0,i),format,width Next image=TImage.Alloc( width,height,1,FILTEREDIMAGE ) image.frames[0]=BRL.Max2D.Blitz2D_Driver.CreateFrameFromPixmap( destpix,FILTEREDIMAGE ) image.masks[0]=destpix Return image End Function
Neat, that should be made into a tiny simple mod for saving pixmaps :P
Hey there, nice code.
But: .masks[0] doesn't seem to work any more in 1.14.
Anyone an idea how to save images to hard drive?
But: .masks[0] doesn't seem to work any more in 1.14.
Anyone an idea how to save images to hard drive?
SavePixmapPNG?
Oh dear this doesn't work as masks[0] gives Compile Error: Identifier 'masks' not found!
Any ideas?
Any ideas?
You should use LockImage(image) to get the pixmap these days.
Aha thanks very much. I'll try that now. Haven't needed to use pixmaps yet.
i always use pixmaps when loading images.
I found in earlier versions of BMX if you tried to load a large image file as an image type it would error, yet when loading the same image file into a pixmap it would work.
Must something to do with the way it stores images elsewhere in mem.
(also loading into pixmap staright away allows me to edit the image)
I found in earlier versions of BMX if you tried to load a large image file as an image type it would error, yet when loading the same image file into a pixmap it would work.
Must something to do with the way it stores images elsewhere in mem.
(also loading into pixmap staright away allows me to edit the image)
Here you go:
Strict Import brl.pixmap Import brl.stream Import brl.EndianStream Function SavePixmapBMP(pixmap:TPixmap,url:Object) Local stream:TStream Local buf:Byte[] Local hsize,hoffset Local size,width,height Local planes,bits,compression,isize,xpels,ypels,cols,inuse Local w,y stream=WriteStream(url) If Not stream Return width=pixmap.width height=pixmap.height w=width*3 w=(w+3)&$fffc hsize=w*height+54 size=40 hoffset=54 planes=1 bits=24 compression=0 isize=40 xpels=2834 ypels=2834 cols=0 inuse=0 stream=LittleEndianStream(stream) WriteByte stream,Asc("B") WriteByte stream,Asc("M") WriteInt stream,hsize WriteInt stream,0 WriteInt stream,hoffset WriteInt stream,size WriteInt stream,width WriteInt stream,height WriteShort stream,planes WriteShort stream,bits WriteInt stream,compression WriteInt stream,isize WriteInt stream,xpels WriteInt stream,ypels WriteInt stream,cols WriteInt stream,inuse buf=New Byte[w] For y=height-1 To 0 Step -1 ConvertPixels(pixmap.pixelptr(0,y),pixmap.format,buf,PF_BGR888,width) stream.WriteBytes(buf,w) Next stream.close() EndFunction