CopyRect and Image Buffers

Blitz3D Forums/Blitz3D Beginners Area/CopyRect and Image Buffers

_PJ_(Posted 2012) [#1]
I'm basically just wanting to load a bunch of single, identically-sized images and re-export them as a single inline imagestrip.
I figured it would be quick and easy (Har Har Har...) to just use Blitz to do this.

However, I seem to just get black 'empty' images. So the Images are created and ecxported okay, The sizes seem okay, just the read buffer data doesn't seem to be written.
From what I can see, the problem may be with CopyRect command when neither the Source/Destination Buffers are the Front/Back Buffers.

The Documentation/Examples doesn't seem at all specific on the issue, and any other results from Searches just seem to use the Front/Back buffers themselves.

Have I missed something (probably painfully blatant) in this code???


Graphics 1024,768,32,2

Const UI_ICONS=21
Const UI_WIDTH=48
Const UI_HEIGHT=48

Const FX_ICONS=11
Const FX_WIDTH=48
Const FX_HEIGHT=48

Global UIImage=CreateImage(UI_WIDTH*UI_ICONS,UI_HEIGHT)
Global FXImage=CreateImage(FX_WIDTH*FX_ICONS,FX_HEIGHT)

MakeUIImage
MakeFXImage

SaveImage(UIImage,"UIpppp.bmp")
SaveImage(FXImage,"FXpppp.bmp")

FreeImage UIImage
FreeImage FXImage

Function MakeUIImage()
	Local Path$="F:\bb\Blitz\WIP\Imgs\"	
	Local Directory=ReadDir(Path)
	Local File
	
	Local FileName$=NextFile(Directory)
	Local FullPath$=""
	Local Frame
	While (FileName$<>"")
		FullPath=Path+FileName
		If (FileType(FullPath)=1)
			If (Len(FileName)>4)
				If ((Left(FileName,2)="UI") And (Right(FileName,4)=".png"))
					Frame=Int(Mid(FileName,3,Instr(FileName,".")-3))
					File=LoadImage(FullPath)
					SetBuffer ImageBuffer(UIImage)
					CopyRect 0,0,UI_WIDTH,UI_HEIGHT,Frame*UI_WIDTH,0,ImageBuffer(File),ImageBuffer(UIImage)
					FreeImage File
				End If
			End If
		End If
		FileName$=NextFile(Directory)
	Wend
	CloseDir Directory
End Function

Function MakeFXImage()
	Local Path$="F:\bb\Blitz\WIP\Imgs\"
	
	Local Directory=ReadDir(Path)
	Local File
	
	Local FileName$=NextFile(Directory)
	Local FullPath$=""
	Local Frame
	While (FileName$<>"")
		FullPath=Path+FileName
		If (FileType(FullPath)=1)
			If (Len(FileName)>4)
				If ((Left(FileName,2)="FX") And (Right(FileName,4)=".png"))
					Frame=Int(Mid(FileName,3,Instr(FileName,".")-3))
					File=LoadImage(FullPath)
					CopyRect 0,0,FX_WIDTH,FX_HEIGHT,Frame*FX_WIDTH,0,ImageBuffer(File),ImageBuffer(FXImage)
					FreeImage File
				End If
			End If
		End If
		FileName$=NextFile(Directory)
	Wend
	CloseDir Directory
End Function


NOTE:They shouldnt exceed the DX image size limitations. I think the largest strip is just over 1000 pixels


Floyd(Posted 2012) [#2]
Be systematic.


Does CopyRect work? Load ONE image, CopyRect to another image, draw both and look.

Are the file names correct? Display them and look.

Are images loaded properly? Draw them and look.

Continue until everything works.


Bobysait(Posted 2012) [#3]
for purpose only :

Graphics 1008,48,0,2

; Create a temporary folder to store temp bmp images
Local rep$="F:\bb\Blitz\WIP\Imgs\temp\"
if filteype (rep)=0 then createdir(rep)

; create some fake icons (48*48 with random color)
Local icon=0
For icon=0 To 20
	Local img=CreateImage(48,48)
	SetBuffer ImageBuffer(img)
		Color Rand(50,255),Rand(50,255),Rand(50,255)
		Rect 0,0,48,48,1
		Color Rand(1,255),Rand(1,255),Rand(1,255)
		Text 24,24,Str(icon),1,1
	SetBuffer BackBuffer()
	; save the icons as bmp
	SaveImage img, rep+"UI"+icon+".bmp"
	; for debug : show the icons
	DrawImage img,icon*48,0
	Flip True
Next

WaitKey
End

this will create some sample-images to test your copyrect thing

Then you can launch your code with this modified function :
Function MakeUIImage()
	Local Path$="F:\bb\Blitz\WIP\Imgs\temp\"
	Local Directory=ReadDir(Path)
	Local File
	
	Local FileName$=NextFile(Directory)
	Local FullPath$=""
	Local Frame
	While (FileName$<>"")
		FullPath=Path+FileName
		If (FileType(FullPath)=1)
			If (Len(FileName)>4)
				If ((Lower(Left(FileName,2))="ui") And (Lower(Right(FileName,4))=".bmp"))
					Frame=Int(Mid(FileName,3,Instr(FileName,".")-3))
					File=LoadImage(FullPath)
					SetBuffer ImageBuffer(UIImage)
					CopyRect 0,0,UI_WIDTH,UI_HEIGHT,Frame*UI_WIDTH,0,ImageBuffer(File),ImageBuffer(UIImage)
					FreeImage File
				End If
			End If
		End If
		FileName$=NextFile(Directory)
	Wend
	CloseDir Directory
End Function



it works for me. If it doesn't for you, then it's probably something wrong from your instalation or your graphics card that does not support something (?)
If it works, then the problem might come from your png images.
Have you tried just drawing them in blitz to be sure they are correctly loaded ?

also, take care of your icons start identifier (I made them start at "0" because you use frame*FX_WIDTH for the copyrect-X-destination)


_PJ_(Posted 2012) [#4]
Hi, sorry I have been away for the last coupla weeks, but I'm back and have done some testing.

I thought I'd see if it may be perhaps something to do with copying from AnimImage frames or various different methods. The following all worked perfectly.



So it seems as though CopyRect itself does indeed function adequately. I know that the fuiles all exist and the names are correct. Bad paths would result in null handles.
With this in mind, I'll try using bitmaps instead of PNGs first, then, if still no luck, perhaps I may just have to splice the images together 'manually'.