Resizing and Freeing Images
BlitzMax Forums/BlitzMax Beginners Area/Resizing and Freeing Images
| ||
This is not a TPixmap question, regular LoadImages. Is there a way to resize, and also release any images that arent needed by BMAX? Equivelant commands to ResizeImage and FreeImage? Thanks, THUMBZ |
| ||
images are stored in the videoram on your actual video card. you can -draw- them are a different size by changing the scale with SetScale, but the only way to truly resize the image bitmap itself is by copying it back into regular RAM, resize it, and abck to video ram: by converting to a pixmap, resize it, and back to an image when you're done. You can release an image though: myimg:timage=loadimage("whatever.jpg") myimg:timage=null ' mark for deletion flushmem ' remove unused objects from memory |
| ||
The resizing sounds complicated, thanks for the freeimages tip. |
| ||
Graphics 640,480 image = LoadImage("max.png",dynamicimage) DrawImage image,0,0 DrawText "Original : " ,0,0 Flip WaitKey() my_pixmap = LockImage(image) my_new_pixmap = ResizePixmap (my_pixmap,100,100) UnlockImage(image) image=LoadImage(my_new_pixmap) WaitKey() Cls DrawImage image,0,0 DrawText "Resized : ",0,0 Flip WaitKey() |
| ||
Wonderfull, I'll have a stab at that. Thanks man. |
| ||
Isn't it faster to write the image to the backbuffer then grab it back into a new image, rather than move it to a pixmap, change it, move it back from a pixmap? |
| ||
It's close. 290ms Pixmap vs 360 Images with debug. 180ms Pixmap vs 220 Images without debug The pixmap results in a cleaner image though. Graphics 640,480 image = LoadImage("max.png",dynamicimage) start_time=MilliSecs() my_pixmap = LockImage(image) xscale# = 1.5 yscale# = 1.5 my_new_pixmap = ResizePixmap (my_pixmap,ImageWidth(image)*xscale,ImageHeight(image)*yscale) UnlockImage(image) image=LoadImage(my_new_pixmap) Cls DrawImage image,0,0 DrawText "Resized : ",0,0 end_time=MilliSecs() total_time = end_time - start_time DrawText "Total_time : " + total_time,0,10 Flip WaitKey() Graphics 640,480 image = LoadImage("max.png",dynamicimage) start_time=MilliSecs() xscale# = 1.5 yscale# = 1.5 SetScale xscale,yscale DrawImage image,0,0 my_image = CreateImage(ImageWidth(image)*xscale,ImageHeight(image)*yscale) GrabImage(my_image,0,0) Cls SetScale 1.0,1.0 DrawImage my_image,0,0 DrawText "Resized : ",0,0 end_time=MilliSecs() total_time = end_time - start_time DrawText "Total_time : " + total_time,0,10 Flip WaitKey() Any mistake spotting or optimisations most welcome |
| ||
Using the pixmap method I did this to get an image to pump. Image size is 64x64Graphics 640,480 Repeat If MouseX()>0 And MouseX()<60 And MouseY()<60 blink() image = LoadImage("media/tiles/first.png",dynamicimage) DrawImage image,0,0 Flip Cls FlushMem Until KeyHit(1) Function blink() For count=1 To 4 image = LoadImage("media/tiles/first.png",dynamicimage) DrawImage image,0,0 Flip Delay 100 my_pixmap = LockImage(image) my_new_pixmap = ResizePixmap (my_pixmap,66,66) UnlockImage(image) image=LoadImage(my_new_pixmap) Cls DrawImage image,0,0 Flip Delay 100 Next End Function Will this cause any problems? Is there another way to pump an image? So if CreateImage is the method used on the backbuffer where is the pixmap operation happening? I'm learning folks - please excuse my ignorance. |
| ||
DrawImageRect draws the entire image into a rectangle at whetever size you want |
| ||
Very good to know. The image looks a bit pixelly. For the 'pump' I would probably use Set Scale rather than using pixmaps. |
| ||
Isn't it faster to write the image to the backbuffer then grab it back into a new image, rather than move it to a pixmap, change it, move it back from a pixmap? The problem with doing it this way is that any transforms and filtering (probably tri-linear) will be passed on to the new image. For resizeing, it's probably not a big deal since you'd want some sort of filtering anyway.However, it would generally be faster to do it all in realtime ala. SetRotation. As for how to free images, that ones real simple. Stop using it. And don't forget to call flushmem once in a while (from as "global" a scope as possible). |