Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / point x,y return image color instead of bitmap

Author
Message
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 28th Jun 2012 23:16
I try to make GUI with buttons being tracked by the color of bitmap over which mouse is. Although this system worked on one of my previous programs, it does fail now. I just don't know whats wrong. All the code looks similar to what I used before, but it don't work. It returns images color, not the bitmap, though, bitmap is set active before acquiring color value

Here are images constants:

File is 1024x768 2.55Mb 24 bit .bmp file

Loading images:


this is the menu function:


Join The dark Side! We have cookies
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 29th Jun 2012 12:24
The POINT command refers specifically to the screen. At least according to the help doc:
Quote: "This command will return the pixel color value from the screen at the specified Coordinates.
"


So unless the image is actually visible on the screen, it won't work (according to the doc). I don't know if you have SYNC on but if you do, you must paste the image and update the screen before using POINT.

May I suggest a simple collision box. It's easy to code.

It's a lot more expedient than using POINT, though granted it is less accurate for non-square buttons.

Hope that helps.

Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Jun 2012 13:06
Yeah you can get colours off a hidden screen, but you seem to switch from the bitmap too quickly....

Set Current Bitmap BMP_MAIN_MENU
ColNumber = Point(Mx,My)
Set Current Bitmap 0

...so you are taking a coordinate from one bitmap, and then switching back to bitmap 0. You need to stay on the hidden bitmap to get the colours before switching back to bitmap 0.

Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 1st Jul 2012 16:13
I forgot to mention that if I use constant BMP_MAIN_MENU 1 then program freezes. It only passed through loading bitmap when set to 0

Join The dark Side! We have cookies
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 2nd Jul 2012 12:32
@Pincho

Why am I too quick? I set my bitmap, get color value, store it in variable, and then reset bitmap. Color from my bitmap should be saved
in variable...

Join The dark Side! We have cookies
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Jul 2012 14:51
Quote: "I forgot to mention that if I use constant BMP_MAIN_MENU 1 then program freezes."


You need to create Bitmap 1, then switch to it, then switch to Bitmap 0. I think that you haven't created Bitmap 1.

Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 3rd Jul 2012 13:12 Edited at: 3rd Jul 2012 13:13
I added a line that creates bitmap. It doesn't help. The freezing problem was missing "sync". Fixed now
I have created separate project to debug only the menu. It acts real strange. I get value of RGBR that is only on one button, on almost whole screen. Mouse x/y are correct.

Join The dark Side! We have cookies

Attachments

Login to view attachments
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Jul 2012 13:30 Edited at: 3rd Jul 2012 13:32
You put SYNC ON `Automatic screen refresh on.

Actually Sync On is Automatic Screen refresh Off. So maybe that is your mistake?

I used to make that mistake when I first got DB Classic.

Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 4th Jul 2012 12:30
I changed to sync off- nothing changed

Join The dark Side! We have cookies
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 4th Jul 2012 15:38 Edited at: 4th Jul 2012 15:48
You need Sync On, but you need Sync to show results. The steps are

Sync On
Make Bitmap 1
Paste Collision on Bitmap 1
Or Load Bitmap 1 with collision.
Get the mouse X/Y
Get the colour with point on Bitmap 1 using Mouse X/Y.
Check colour for collision colours
Switch to Bitmap 0
Paste images on Bitmap 0
Sync
Activate collision Gosubs if needed

Here's a working example....

Attachments

Login to view attachments
Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 5th Jul 2012 16:39
OMFG I found the problem and it is SO WEIRD

I tried to put Pinchos code in my code, and accidently found out that my "loading" image is below my top layer image with buttons. It disappeared only when I delete all lines that paste image in function that loads other images. I have no idea why that image is left there. And why point function takes color values from that image but not from bitmap. When image disappeared, all the color values were taken correctly from bitmap.

Now I start thinking how to paste image when loading all the stuff and not to bug menu. Black window doesn't look nice, nor informative.

And another thing- Pincho used jpg image for bitmap. That's cool. I thought only .bmp format it good for that. Using JPGs will decrease my programs size. Yey!

Join The dark Side! We have cookies
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Jul 2012 17:54
Quote: "And another thing- Pincho used jpg image for bitmap. That's cool. I thought only .bmp format it good for that. Using JPGs will decrease my programs size. Yey!"


The jpg colours change from bmp colours. You just have to test the colours first to see what they have changed to.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Jul 2012 19:20
JPG uses lossy compression which means you'll have a loss in quality and lose precision with all of your shapes you may have on the image. I suggest you use PNG images, they have a loss-less compression algorithm.

This guy explains it really well : http://www.r1ch.net/img-formats/

TheComet

Kiaurutis
13
Years of Service
User Offline
Joined: 19th Jan 2011
Location: Lithuania
Posted: 6th Jul 2012 17:25
It was useful to read the article about image formats. From now on, I will be using PNG's - they are even smaller than JPG's and quality loss-less

I called function "CLS" to clear screen after loading images and now everything works how it should. Dunno why it is not required after loading that image second time in my function...



And a little function to avoid runtime errors while loading images:



Thx for help guys, it really helped to fix and improve my code

Join The dark Side! We have cookies

Login to post a reply

Server time is: 2024-11-22 00:06:39
Your offset time is: 2024-11-22 00:06:39