Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 009:_PutImage
#1
Here is what it looks like in Wiki:

Quote:_PUTIMAGE [STEP] [(dx1dy1)-[STEP][(dx2dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1sy1)[-STEP][(sx2sy2)]][_SMOOTH]


Yikes! but all we are doing is copying an image from Source Image Handle and rectangular section to Destination Image Handle and rectangular section.

After working with it for awhile now this is what I see:
(for the moment ignore all that STEPping)

_PutImage rectangle, handle, handle, rectangle
2 line rectangles on either end of the parameters.
2 Image handles in the middle of the parameters.

What belongs to what, the order is: D,S,D,S 
D for Destination where you want the rectangle image to go.
S for Source where the image is coming from.
(Kind of an odd sequence but... let us continue.)

Now Rectangle knowledge from working with Line (left, top)-(right, bottom) format comes in handy here (as does the practice with Step). (top, left) corner to (bottom, right) corner defines the rectangle space we are grabbing from Source and then pasting into the Destination.

If you want to fill the whole destination rectangle with the image, leave destination rectangle blank and it will fill the destination image by default. Same with the other end, if you want to use the whole image from the Source handle leave the Source rectangle blank as default.

Where do image handles come from?
Well most important is the current screen image, it is 0 automatically.
You can start an Image handle, say IH& Long Type from
IH& = _LoadImage("Filename.ext")
or
IH& = _NewImage(width, height, colorMode) ' starts a container to draw and/or _PutImage and/or start font and print.

STEP allows you to use the last graphics command (x, y) as the start for the next graphics, a very handy use of step for images is to start with the (x,y) location of the top left corner of the rectangle and -Step(ImageWidth, ImageHeight) instead of adding width to x height to y and finding the absolute position value for the 2nd (x, y).

I think this covers the most common uses of _PutImage there are plenty more details to go over, maybe pick those off with discussion?
b = b + ...
Reply
#2
One of the easiest uses of _PutImage is for a background of your screen.

Here I am using the qb64pe.png logo image you can find in your QB64pe Source Folder:
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

'  fill entire screen with stretched out logo
_PutImage , Logo&, 0

   
b = b + ...
Reply
#3
Now using actual size of image, center it onto screen:
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

' put image, the actual size, into the middle of our screen
_PutImage ((_Width - .5 * _Width(Logo&)) / 2, (_Height - .5 * _Height(Logo&)) / 2), Logo&, 0

   

Notice: if you don't specify the bottom right corner the actual image rectangle size is used. Above I just told _PutImage the (Left, Top) corner.


Whoa pretty small! Have to do something about that...
b = b + ...
Reply
#4
Thus the chain of obscure or almost-worthless commands established by Steve is broken...

This "_PUTIMAGE" is a keyword where Galleon displayed his stripes. I think M$ would have priced QuickBASIC higher if they had to do something like this, or if they thought it would have given them better sales for Visual Basic LOL. BASIC PDS v7.1 had "far" strings which were less useful than an image and/or sound statement... I was never able to take advantage of those "far" strings. In fact disliked "QBX" program, it just didn't match but only if Programmer's Workbench weren't so slow on my Tandy1000 RLX. :crying:

Sometimes, however, using "_PUTIMAGE" could be clunkier than the old "GET" and "PUT" which haven't really gotten with the times. Good for sprites but Freebasic is a bit better here. But I wouldn't give up "_PUTIMAGE" for anything in the world if I were even deeper than Terry Ritchie doing arcade games and without pay.
Reply
#5
I like to use _PUTIMAGE but didn't know about the STEP. I'd like to see an example of this.
Reply
#6
Sure with Step, I will magnify the image by 5 and keep it centered on screen and preserve the ratio of Width to Height:
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

scale = 5 ' we are going to magnify the image by 5 and preserve the ratio of width to height
scaleW = scale * _Width(Logo&) '
scaleH = scale * _Height(Logo&)

' put image, the actual size, into the middle of our screen
_PutImage ((_Width - scaleW) / 2, (_Height - scaleH) / 2)-Step(scaleW, scaleH), Logo&, 0

   
b = b + ...
Reply
#7
(11-15-2022, 12:32 AM)bplus Wrote: Now using actual size of image, center it onto screen:
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

' put image, the actual size, into the middle of our screen
_PutImage ((_Width - .5 * _Width(Logo&)) / 2, (_Height - .5 * _Height(Logo&)) / 2), Logo&, 0



Notice: if you don't specify the bottom right corner the actual image rectangle size is used. Above I just told _PutImage the (Left, Top) corner.


Whoa pretty small! Have to do something about that...
With you so far...  Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#8
Checking out access to the Source Image, let's see if we can isolate the QB64 image in the middle third across and 1/3 down from top of QB64pe Logo. Yes and have a little fun with it! Smile
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

' OK lets see if we can isolate the QB64 print from the Source side
' it looks to be the middle 1/3 going across and the top 1/3 going down

xThird = _Width(Logo&) / 3
yThird = _Height(Logo&) / 3

_PutImage , Logo&, 0, (xThird - 2, 0)-Step(xThird + 3, yThird + 1)
For y = 6 To _Height - 1 Step 2 * (yThird + 3)
    For x = 10 To _Width - 1 Step 2 * (xThird + 3)
        _PutImage (x, y), Logo&, 0, (xThird - 2, 0)-Step(xThird + 3, yThird + 1)
    Next
Next
Sleep

EDIT: expanded the area of grab off source by pixels for fuller letters and digits.
   
b = b + ...
Reply
#9
(11-15-2022, 01:49 AM)bplus Wrote: Checking out access to the Source Image, let's see if we can isolate the QB64 image in the middle third across and 1/3 down from top of QB64pe Logo. Yes and have a little fun with it! Smile
Code: (Select All)
Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors
_Delay .2
Logo& = _LoadImage("qb64pe.png")

' OK lets see if we can isolate the QB64 print from the Source side
' it looks to be the middle 1/3 going across and the top 1/3 going down

xThird = _Width(Logo&) / 3 ' = 1/3 width
yThird = _Height(Logo&) / 3

_PutImage , Logo&, 0, (xThird - 1, 0)-Step(xThird + 1, yThird + 1)
For y = 10 To _Height - 1 Step 2 * (xThird + 3)
    For x = 10 To _Width - 1 Step 2 * (yThird + 3)
        _PutImage (x, y), Logo&, 0, (xThird - 1, 0)-Step(xThird + 1, yThird + 1)
    Next
Next
sleep



Oh looks like a pixel short at least on the Q side, a little flat. I will try and fix?
Is this picture depicting the recent diversification of QB64?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#10
I was just practicing isolating a familiar image from the Logo. Don't take this politically.

I am also appreciating more the work put into the Phoenix image.
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)