|
Post by bplus on Oct 30, 2023 0:18:44 GMT
To help aquiant you with the very handy keyword _PutImage. First we need an image, how about the QB64 Logo? Copy and save this or you can find it in QB64 / Source folder And the simplest thing we can do with _PutImage is use an Image for background to whole screen: Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors _Delay .2 Logo& = _LoadImage("qb64.png")
' fill entire screen with stretched out logo _PutImage , Logo&, 0 ' 0 is the default handle for the main screen In this form of PutImage we see the 2 main components of _Putimage 1) the handle for the source image Logo& and 2) the handle for the Destination of the image, 0, which is the default Screen. (You can draw images with PutImage independent of the screen using _NewImage() and some other stuff but that is for another lesson.)
|
|
|
Post by bplus on Oct 30, 2023 0:28:53 GMT
For demo 2, lets take the actual size of the image and center it on our 800 x 600 demo screen. With Logo& the handle for our image _Width, _Height keywords tell us screen size but can also work for images _Width(Logo&), _Height(Logo&) To center anything take the whole length across and subtract the length of item to be centered, take half of that for where we start the item to insert. This works for across and vertically. If we just tell _putImage the Top, Left corner of where we want the image to go, it will figure the rest from the actual image size. Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors _Delay .2 Logo& = _LoadImage("qb64.png")
' put image, the actual size, into the middle of our screen _PutImage ((_Width - _Width(Logo&)) / 2, (_Height - _Height(Logo&)) / 2), Logo&, 0
|
|
|
Post by bplus on Oct 30, 2023 0:37:03 GMT
For demo 3 with PutImage let us center the image in a real small window in the middle of the screen and increase the size of the window for the image. To do this, we tell _PutImage the left,top corner of where we want it PLUS the right, bottom corner where we want to squeeze or stretch the image to fit. Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors _Delay .2 Logo& = _LoadImage("qb64.png")
For scale = .1 To 2.1 Step .1 Cls ' we are going to magnify the image by scale 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 Print "press any for next size..." Sleep Next Here is a snap of the first tiny window in the middle of the screen: Run the program and everytime you press a key the image will grow remaining centered in the screen. Step(dx, dy) for right, bottom corner works just the same as it does when we draw a rectangle with Line(,)-(,) using the B or BF option Step(dx, dy) takes the last (x, y) and adds dx to x and dy to y to get absolute point for right bottom corner.
|
|
|
Post by bplus on Oct 30, 2023 0:58:51 GMT
For Demo 4 we are going to work with Source side of the PutImage command, to the right of the 2 image handles in the middle. Before we were just dealing with the destination side of PutImage, the rectangle corners left of the 2 image handles in the middle. The source side of _PutImage can pick out a smaller window section of the source image using rectangle left, top and right, bottom corners just as we did with the destination side of PutImage. Let us isolate the B in the QB64 Logo, that would be in top and right half sides of Logo. Let us project that B over the whole window first, one giant B then let us project that B image in rectangular sections throughout the window like a grid. Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors _Delay .2 Logo& = _LoadImage("qb64.png")
' OK lets see if we can isolate the B in QB64 print from the Source side ' it looks to be the middle 1/2 going across and the top 1/2 going down
xHalf = _Width(Logo&) / 2 yHalf = _Height(Logo&) / 2
_PutImage , Logo&, 0, (xHalf - 1, 0)-Step(xHalf, yHalf) Print "Press a key for a grid of little B's..." Sleep For y = 0 To _Height - 1 Step yHalf For x = 0 To _Width - 1 Step xHalf _PutImage (x, y)-Step(30, 30), Logo&, 0, (xHalf - 1, 0)-Step(xHalf, yHalf) Next Next Sleep
|
|
|
Post by bplus on Oct 30, 2023 1:08:01 GMT
And finall for demo 5, let us use PutImage to reflect an image on the x axis and the y axis and both x and y axis, like an mirror image reflected in a still lake. This is a little tricky but you do this by flipping the corner points just so: Screen _NewImage(800, 600, 32) ' screen width, height, 32 is _RGBA colors _Delay .2 Logo& = _LoadImage("qb64.png")
scale = .75 ' we are going to magnify the image by .755 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
' flip image mirror on x and y axis _PutImage (_Width / 2, _Height / 2 - scaleH)-Step(scaleW, scaleH), Logo&, 0 _PutImage (_Width / 2, _Height / 2 - scaleH)-Step(-scaleW, scaleH), Logo&, 0 _PutImage (_Width / 2, _Height / 2 + scaleH)-Step(scaleW, -scaleH), Logo&, 0 _PutImage (_Width / 2, _Height / 2 + scaleH)-Step(-scaleW, -scaleH), Logo&, 0
|
|
abram
New Member
Posts: 44
|
Post by abram on Oct 30, 2023 18:07:34 GMT
Here is what I did after looking at some tutorial's. Does it look right?
DesktopImage& = _NewImage(1200, 750, 32) Screen DesktopImage& Color , 3 Cls Print "WORLD HERE" DesktopImage2& = _CopyImage(DesktopImage&) ImageTwo& = _NewImage(400, 400, 32) _Dest ImageTwo& Color , 4 Cls Print "HELLO" Sleep _PutImage (0, 0)-(400, 400), ImageTwo&, DesktopImage&, (0, 0)-(400, 400) Sleep _Dest DesktopImage& _FreeImage ImageTwo& Sleep Cls Sleep _PutImage (0, 0)-(1200, 750), DesktopImage2&, DesktopImage&, (0, 0)-(1200, 750)
|
|
|
Post by bplus on Oct 30, 2023 19:17:36 GMT
No doesn't look like anything so doubt it is "right".
First off when you use 32 for colorPalette in _NewImage(x_width, y_height, colorpalette) you are calling for _RGB32(red, green, blue) where red, green blue = 0 to 255. So CLs , 4 and cls , 3 are going to be 2 screened colors very close to black!
If you want to use 1 or 2 digit colors call color palette 12, like in screen 12 (though it takes _Rgb32 too I think).
So what is goal of demo? Place an image of what on an image of what?
I will write some code that makes a random background of stuff and then make an image of a yellow triangle and center it over the random background. BRB
|
|
|
Post by bplus on Oct 30, 2023 20:11:42 GMT
Draw a background then save it in image handle. Then clear screen then draw yellow triangle in upper left corner and save that in image handle. Then draw background and lay the triangle right in the middle of the screen. _Title "PutImage Demo 6" 'b+ 2023-10-30 Screen _NewImage(800, 600, 32)
' make a background of random filled or not boxes of random colors For i = 1 To 300 x = _Width * Rnd: y = _Height * Rnd: w = Rnd * 100 + 10: h = Rnd * 100 + 10 rd = Rnd * 255: gn = Rnd * 255: be = Rnd * 255 If Rnd < .5 Then Line (x, y)-Step(w, h), _RGB32(rd, gn, be), BF Else Line (x, y)-Step(w, h), _RGB32(rd, gn, be), B End If Next 'save this for background background& = _NewImage(_Width, _Height, 32) _PutImage , 0, background&
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0, 0) ' back color is still 0 = transparent !!! _PrintString (150, 300), "This will be our background, press any for triangle object" Sleep
Color , 0 ' <<<<<<<<<<<<<<<<<<< this is not black it is transparent = _RGB32(0, 0, 0, 0) Cls x1 = 10: y1 = 10 x2 = 90: y2 = 50 x3 = 10: y3 = 90 Line (x1, y1)-(x2, y2), _RGB32(255, 255, 0) Line (x2, y2)-(x3, y3), _RGB32(255, 255, 0) Line (x3, y3)-(x1, y1), _RGB32(255, 255, 0) Paint (50, 50), _RGB32(255, 255, 0), _RGB32(255, 255, 0) ' save this for triangle triangle& = _NewImage(100, 100, 32) _PutImage , 0, triangle&, (0, 0)-(99, 99) Color _RGB32(255, 255, 255), 0 ' back color is still 0 = transparent !!! _PrintString (5, 300), "This will be our triangle object." _PrintString (5, 320), "press any to place triangle on top of background" _PrintString (5, 340), "Near center of screen..." Sleep Cls _PutImage , background&, 0 _PutImage (400 - 50, 300 - 50), triangle&, 0
|
|
abram
New Member
Posts: 44
|
Post by abram on Oct 30, 2023 21:14:49 GMT
So, in the code below: triangle& = _NewImage(100, 100, 32) this line makes a "new image" with the needed dimensions
and
_PutImage , 0, triangle&, (0, 0)-(99, 99) this line makes the image on the screen @(0,0)-(99,99) goto the handle of triangle&
' save this for triangle triangle& = _NewImage(100, 100, 32) _PutImage , 0, triangle&, (0, 0)-(99, 99)
Where do "_Dest" and "_FreeImage" come into play?
I was thinking free image or dest had to do with making a sprite for a menu system. I'm just trying to figure out the best way for a system with text on the screen. I want to avoid screen tare or ghost images too.
|
|
|
Post by bplus on Oct 30, 2023 23:33:15 GMT
OK I could have drawn the triangle in a private little space setup with tri& = _NewImage(100, 100, 32) Then set destination (for all future graphics commands) to the _dest tri& 'draw triangle then returned to main screen _dest 0 that's where _dest comes in, telling QB64 where you are sending your drawing commands _dest 0 is main screen. _FreeImage is for when you are done using a graphic image you want to free up memory and then reuse the handle maybe for another temp image. _FreeImage handle& The above does that and handle& could then be used again for something else. If you don't use _FreeImage AND do use handle& for another image you will create a memory leak and your program will crash if suck up all the memory computer has! Now, as for doing stuff with text, what better is there than _printString(x, y), text Oh perhaps you should checkout _PrintMode specailly handy is _printMode _KeepBackground You won't get those ugly label maker effects where backcolor for printed text doesn't match the screen back color!
|
|