Link to home
Start Free TrialLog in
Avatar of SaadKhakwani
SaadKhakwani

asked on

want to get the bitmap behind a picture box !!!

Hello,
I want to retrieve the bitmap behind a picture box, i mean there is a command button and a text box for example, on a form. Now a picture box is placed just as it is in front of the command button and the text box. I have to get the bitmap of the same coordinates as of the picturebox, i.e what is the image beneath that pic. box.
I have tried different techniques but failed, one such was to make the pic. box invisible (Picture1.Visible = False) and then get the hdc of the form1 and Paint in Pic. Box using BitBlt, then True its Visible Property. and then alpha blend to make the picture1 *look* translucent!

That is good when the picturebox is static but when we want it to move, or the background picture of form1 is changed. It fails, or even if we update the code every time, that toggling of visibility causes the picture to flicker.!
Any Comments,
Thanks.
Saad.
Avatar of Kokoglen
Kokoglen
Flag of United States of America image

What program are you using?
Avatar of SaadKhakwani
SaadKhakwani

ASKER

I am trying to do that in Visual Basic!
ASKER CERTIFIED SOLUTION
Avatar of Goofytouy
Goofytouy
Flag of Uruguay image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Goofytouy:
i am saying that there is a form. I have loaded a picture into it,

Form1.Picture = LoadPicture(whatever)

Now textbox, commandbutton and picturebox all are on that form, but picturebox is on top of textbox and command button i.e

Picture1.ZOrder 0
All are contained in the form!
PictureBox doesn't contain Anything!

Here i want to add the code as, the Picture1, becomes translucent. I could see the textbox and commandbutton and whatever the image is on the form, through the Picturebox,
Retrieving the hDC of the Form1 by using GetDC(Form1.hWnd), also gives the image of the Picturebox because that is also on the Form1. turning the picturebox invisible does the trick because if picturebox is invisible, the hDC of the form thus generated wont show picturebox, but all else control do. Now BitBlt the hDC of the Form1 to fit in pictureBox, so that the part of the Form1's hDC which shows the part of other controls (which were actually beneath the PictureBox) comes in Picture1!!! AlphaBlend if required to make the image more translucent!
Then turn the picture1.Visible = True!

That algorithm is ok if things are static, but when the textbox or commandbutton moves the picture of the Picture1 is not updated! or even if we do update! The repeated toggling of picture1 from visible to invisible cause it to flicker badly!
that was one poor way of making a picturebox translucent!, but if someone knows better, please tell me!!!
As far as I understand (let me say is difficult because I can no imagine what would be the point), you are going to have flicker in every case. At least, you should take it to the minimum by updating picture1 only as necessary. let's say you may code a function "updatepicture1" and call it from "form_activate", "form_resize" and other "rupture points" (remember to code an UDF for checking the contents of form1.picture)

But as said before, eliminating flicker is imposible as VB redraws all in every change...
Avatar of turn123
SaadKhakwani,
No comment has been added lately (80 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to Goofytouy http:#9671278

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

turn123
EE Cleanup Volunteer