As I know, basically there is no built in command to resize images in FB, although users implement this with own codes.
I made one too, but it's not perfect for some reason, because as if it would rotate the image.
I don't want reinvent the wheel, but I'm curious about the cause of the error and do you think this is a useful code?
Code: Select all
#if __FB_LANG__ = "qb"
#define EXTCHAR Chr$(0)
#else
#define EXTCHAR Chr(255)
#endif
#include "fbgfx.bi"
Using FB
dim shared as any ptr src_img,dest_img
dim shared as ubyte di_size=1 'Size of destination image
screenres 640,480,32
sub resize_img()
dim as long result,w,h
dim as integer xp,yp
ImageDestroy dest_img
result = imageinfo(src_img, w, h)
dest_img=ImageCreate(w*di_size,h*di_size)
xp=0
yp=0
for i as integer=0 to w-1 'Width
for j as integer=0 to h-1 'Height
for x as integer=xp to xp+di_size
for y as integer=yp to yp+di_size
PSet dest_img,(x,y),Point(i,j,src_img)
next y
next x
if xp+di_size<=w*di_size then
xp+=di_size
else
xp=0 : yp+=di_size
end if
next j
next i
end sub
'Creating a 32*32 size smiley as source image:
src_img = ImageCreate( 32, 32, RGB(255, 0, 255) )
Circle src_img, (16, 16), 15, RGB(255, 255, 0), , , 1, f
Circle src_img, (10, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle src_img, (23, 10), 3, RGB( 0, 0, 0), , , 2, f
Circle src_img, (16, 18), 10, RGB( 0, 0, 0), 3.14, 6.28
resize_img()
Do
var k = Inkey$
Select Case k
Case EXTCHAR & "H" 'Up arrow
if di_size<10 then
di_size+=1
resize_img()
end if
Case EXTCHAR & "P" 'Down arrow
if di_size>1 then
di_size-=1
resize_img()
end if
end select
screenlock
cls
Put (16, 32), src_img, Trans
Put (320, 240), dest_img, Trans
draw string (1,1),"Use UP and DOWN arrow keys to resize image; ESC to exit."
draw string (1,12),"Size of the destination image: "+str(di_size)
screenunlock
loop until multikey(sc_escape)
ImageDestroy src_img
ImageDestroy dest_img