How can i resize an image without loading it?

Blitz3D Forums/Blitz3D Programming/How can i resize an image without loading it?

dman(Posted 2010) [#1]
I'm drawing an image on the screen using the buffers and draw image.

I want to resize it , how can I.


Robert Cummings(Posted 2010) [#2]
paint package?


Matty(Posted 2010) [#3]
the blitz command resizeimage?


D4NM4N(Posted 2010) [#4]
He said without loading it.

To be honest you can't, even if you do it via a file byte read into a buffer or arrays for processing you are still technically loading it, just avoiding the loadimage command.

Why do you need to do this? Is it some special system where you do not want to invoke the graphics or something? otherwise as aboves have said, best option is paint package (try this www.gimp.org it's free and quite featured) or resize image.

Last edited 2010


jfk EO-11110(Posted 2010) [#5]
We had a little inofficial "faster image resize" contest some time ago and there were two code samples, one by me, that were several times faster than the native command. Mine was using a 3D render and due to mipmapping it is also highly "TFormFiltered" but it is limited to the Graphics Size : http://www.blitzbasic.com/codearcs/codearcs.php?code=1305.

I am sure it must be easy to use it without to load the image.


Matty(Posted 2010) [#6]
I don't understand?

I'm drawing an image on the screen using the buffers and draw image.


Simply grabimage the image on the screen the use the resize image command, no need to call loadimage???


big10p(Posted 2010) [#7]
You can't display or resize an image without loading it. The data needs to be in memory at some point in order to operate on it. What am I missing here?


Matty(Posted 2010) [#8]
I'm not sure I follow. I think we have a different idea of 'loadimage'. I thought the original poster wanted to know how to draw an image without using the 'loadimage' command - in which case you simply 'createimage(width,height)' then write to it pixel by pixel using whatever method he wants, and then can resize that image - and the loadimage command has not been used.

Unless he means - how can I resize an image that is not in memory...which doesn't really make sense - how did it get drawn if it is not in memory in the first place???

Sorry, maybe I'm just dense but I don't follow what the original poster means...


dman(Posted 2010) [#9]
I'm trying to use ResizeImage and CreateImage without using LoadImage.

I get an image do not exist error. How can I resize an image?

Last edited 2010


Matty(Posted 2010) [#10]
Here's a simple example:
Graphics 800,600,0,2
image=CreateImage(256,256)
SetBuffer ImageBuffer(image)
; draw to your image as you would choose too
For n=1 To 10
	Color 31+Rand(32)*7,31+Rand(32)*7,31+Rand(32)*7
	Rect Rand(256),Rand(256),Rand(32),Rand(32)
Next
SetBuffer BackBuffer()
Cls
DrawImage image,0,0
Flip
WaitKey
ResizeImage image,512,512
Cls 
DrawImage image,0,0
Flip
WaitKey



Rob the Great(Posted 2010) [#11]
Give this a try.
Graphics 640,480,0,2

SetBuffer BackBuffer()

Global image = CreateImage(100,100)

SetBuffer ImageBuffer(image)

ClsColor 255,255,255

Cls

SetBuffer BackBuffer()

ClsColor 0,0,0

Global size = 1

While Not KeyDown(1)

	Cls
	
	If KeyHit(57)
		If size = 1
			ResizeImage image,50,50
			size = 2
		EndIf
		If size = 0
			ResizeImage image,100,100
			size = 1
		EndIf
		If size = 2
			size = 0
		EndIf
	EndIf
	
	DrawImage image,320,240
	
	Text 0,0,"Press Space to Resize Your Image You've Created."
	
	If size = 1
		Text 0,20,"Size: LARGE."
	EndIf
	
	If size = 0
		Text 0,20,"Size: SMALL."
	EndIf
	
	Flip

Wend

End

It's working for me, so I'm not sure what's going on. It's probably a dumb point to make, but please double check your image handles that they match throughout the program. I overlook easy typos so many times, it's rediculous. Also, if you need to access the image again in a function after it was created in the main program, it has to be declared Global in order for Blitz to recognize the variable name later on.

Like I said, you probably did both of those, so I'm not sure where you're running into problems.


Rob the Great(Posted 2010) [#12]
Ah, Matty beat me to it.


dman(Posted 2010) [#13]
that do not work, you have to use LoadImage to use ResizeImage.


dman(Posted 2010) [#14]
the help files say you can not use ResizeImage without using LoadImage,
have to load it first.


Matty(Posted 2010) [#15]
I'm sorry but I just ran the code then and it worked fine?
What version of blitz3d are you using?


dman(Posted 2010) [#16]
I'm using version 1.64 with update 1.106


dman(Posted 2010) [#17]
what version do you have?


Rob the Great(Posted 2010) [#18]
I ran both examples fine with 1.100. It wouldn't be a bug, would it? It seems odd that a bug would appear on a newer version. Did you try copying and pasting the example into your copy of Blitz to see if they ran? If it still fails, I'm stumped at that point.

Last edited 2010


_PJ_(Posted 2010) [#19]
I'm using v1.106 and it (both sets of code in fact) works fine.

There's no reason, really why ReSizeImage shouldn't work with a 'Created' image as opposed to a Loaded one. I would guess the help files just mean that you need AN image in memory, or are based on an earlier version?

Perhaps there's an issue with some newer graphics drivers neglecting some old DX7 2D functionality?


Matty(Posted 2010) [#20]
I don't think dman has tried the code, I think he has just read the online docs or offline docs which he has misinterpreted to read as if saying that only an image loaded from an external file can be resized...


Rob the Great(Posted 2010) [#21]
hehe, that would be funny. dman, any luck?


dman(Posted 2010) [#22]
it works on a original image, but when I use the copyimage and then resize the copied one, I get weird results.

I'm using this code I found in the forum. but I need to calc. the size to fit inside a fixed rectangle. do I use the Imagewidth with some kind of calc. with the length of the rectangle? The length of the image varies in size, I want to get it a size to fit the rectangle length.

heres the code :



Function ResizeImageb(imageb, newwidth, newheight, frame = 0)
tbuffer = GraphicsBuffer()
oldwidth = ImageWidth(imageb)
oldheight = ImageHeight(imageb)
ni = CreateImage(newwidth + 1, oldheight)
dest = CreateImage(newwidth, newheight)
SetBuffer ImageBuffer(ni)
For ix = 0 To newwidth
	DrawBlockRect imageb, ix, 0, Floor(oldwidth * ix / newwidth), 0, 1, oldheight, frame
Next
SetBuffer ImageBuffer(dest)
For iy = 0 To newheight
	DrawBlockRect ni, 0, iy, 0, Floor(oldheight * iy / newheight), newwidth, 1
Next 
FreeImage ni
SetBuffer tbuffer
Return dest
End Function



Last edited 2010

Last edited 2010


_PJ_(Posted 2010) [#23]
I'm really- not sure wqhat you're trying to do with this...

If you just want to resize an image buit maintain the original, why not just:

Function ResizeImageCopy(Image,NewWidth,,NewHeight)
	Local NewImage=CopyImage(Image)
	ResizeImage NewImage,NewWidth,NewHeight
	Return NewImage
End Function


Instead of CopyImage, you could perhaps use some of the fast buffer functions?


I'm quite confused by this whole thread... What EXACTLY are you wanting to achieve as the end result with all this stuff, dman? If I can understand your aim, I could help with getting there!