;Read Data Write Image, on 21/9/06Graphics3D 640,480,0,2SetBuffer BackBuffer()Restore yourname_bmp ;image data labelimage=ReadDataWriteImage() ;image out;Main loopWhile Not KeyHit(1) Cls DrawImage image,50,50 ;draw image out Text 0,0,"width="+ImageWidth(image)+" height="+ImageHeight(image) FlipWend;IncludesInclude "temp.bb";FunctionsFunction ReadDataWriteImage() ;Read a data label, create image and write 24-bit color data Local imagesize,width,height,image,buffer,i,integer,count,rgb,x,y,ix ;create image Read imagesize ;first value is width/height width=imagesize And $0000FFFF height=(imagesize And $FFFF0000) Shr 16 image=CreateImage(width,height) buffer=ImageBuffer(image) ;write pixels from 8-bit run/24-bit color integer LockBuffer buffer While i<width*height Read integer count=integer And $000000FF rgb=(integer And $FFFFFF00) Shr 8 For x=ix To ix+count-1 WritePixelFast x,y,rgb,buffer Next ix=ix+count i=i+count If ix>=width Then y=y+1 : ix=0 Wend UnlockBuffer buffer Return image ;image handleEnd Function
;Read Data Write Texture, on 21/9/06Graphics3D 640,480,0,2SetBuffer BackBuffer()camera=CreateCamera()light=CreateLight()RotateEntity light,45,45,0Restore yourname_bmp ;image data labeltex=ReadDataWriteTexture() ;texture outcube=CreateCube()PositionEntity cube,0,0,5EntityTexture cube,tex;Main loopWhile Not KeyHit(1) RenderWorld TurnEntity cube,0.4,0.3,0.2 Text 0,0,"width="+TextureWidth(tex)+" height="+TextureHeight(tex) FlipWend;IncludesInclude "temp.bb";FunctionsFunction ReadDataWriteTexture() ;Read a data label, create texture and write 24-bit color data Local texsize,width,height,tex,buffer,i,integer,count,rgb,x,y,ix ;create texture Read texsize ;first value is width/height width=texsize And $0000FFFF height=(texsize And $FFFF0000) Shr 16 tex=CreateTexture(width,height) buffer=TextureBuffer(tex) ;write pixels from 8-bit run/24-bit color integer LockBuffer buffer While i<width*height Read integer count=integer And $000000FF rgb=(integer And $FFFFFF00) Shr 8 For x=ix To ix+count-1 WritePixelFast x,y,rgb,buffer Next ix=ix+count i=i+count If ix>=width Then y=y+1 : ix=0 Wend UnlockBuffer buffer Return tex ;texture handleEnd Function