|
-
Jul 16th, 2001, 01:26 AM
#1
Thread Starter
New Member
Help with blitting to picture box
I need some help please.
I have a form with a picturebox on it, and what I need is some code to do the following:
MouseDown - Copy whatever is in the picturebox into a spot in memory.
MouseMove - Blit whatever is in the memory back to the picturebox.
MouseUp - Delete whatever was in memory.
I have tried playing around with CreatecompatibleDC and CreateCompatibleBitmap, but I just don't understand where I'm going wrong (maybe I just don't understand it at all). Any help would be muchly appreciated.
Thanks.
Please please please help.
Last edited by kiwisheep; Jul 17th, 2001 at 05:38 PM.
-
Jul 17th, 2001, 11:11 PM
#2
Thread Starter
New Member
Can anyone help? I didn't think it would be that hard a question!! All I need is some code to create a device context in memory, and code to copy the contents of a picture box to that device context, and some code to delete the device context when I'm finished. Please please please....
-
Jul 18th, 2001, 05:21 AM
#3
Addicted Member
have a look here for infomation about releasing DC's
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jul 18th, 2001, 06:06 AM
#4
Thread Starter
New Member
Maybe if I posted some of my code someone might be able to tell me where I'm going wrong...
Code:
Private Sub picGrid_MouseUp(button As Integer, shift As Integer, x As Single, y As Single)
SelectObject hDCTmp, HBMPrv
DeleteObject hBMTmp
DeleteDC hDCTmp
End Sub
Private Sub picGrid_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)
If button = 1 Then
intStartx = x \ 20
intStarty = y \ 20
intEndx = intStartx
intEndy = intStarty
intOldEndx = intStartx
intOldEndy = intStarty
hDCTmp = CreateCompatibleDC(picGrid.hdc)
hBMTmp = CreateCompatibleBitmap(picGrid.hdc, picGrid.ScaleWidth, picGrid.ScaleHeight)
HBMPrv = SelectObject(hDCTmp, hBMTmp)
picGrid.Circle (intStartx * 20 + 6, intStarty * 20 + 9), 10, RGB(255, 0, 0)
End If
End Sub
Private Sub picGrid_MouseMove(button As Integer, shift As Integer, x As Single, y As Single)
If button = 1 Then
intEndx = x \ 20
intEndy = y \ 20
If intOldEndx <> intEndx Or intOldEndy <> intEndy Then
BitBlt picGrid.hdc, 0, 0, picGrid.ScaleWidth, picGrid.ScaleHeight, hDCTmp, 0, 0, vbSrcCopy
Basically, what it should do is when I click, it puts a copy of what is in the picture box in memory, then draws on it. Whenever I move the mouse, I want it to draw back the original picture, then draw on it some more, but all I get at the moment when I blit back is just garbled, not what was there originally - can anyone see where I've gone wrong?
-
Jul 18th, 2001, 09:36 AM
#5
Addicted Member
far too many variables for my liking.
try adding:
BitBlt hDCTmp, 0, 0, picGrid.ScaleWidth, picGrid.ScaleHeight, picGrid.hdc, 0, 0, vbSrcCopy
after compatible DC line
Also try adding two picture boxes and copying the contents of memory into picturebox2 to see if the tempDC is being created Properley
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jul 18th, 2001, 05:17 PM
#6
Thread Starter
New Member
hmmm....I've tried your suggestions but it makes no difference. When I add the second picture box, it just blits the same rubbish to that as well. I can make it blit from the first picture box to the second, and then back again, but I don't want the second picture box to be visible, and if it's not visible, it just blits back the picture of the form where the invisible picture box is. Where oh where am I going wrong?
-
Jul 18th, 2001, 05:27 PM
#7
If you set the AutoRedraw property to true for the PicBox you don't won't visible, that should solve you're problem.
-
Jul 19th, 2001, 05:09 AM
#8
Addicted Member
Try Blting in the Image after CreateCompatibleBitmap, not DC, sorry.
I pretty sure the createbitmap, just defines a bitmap rather that makes a copy.
Some Days, i just get this feeling that i'm helping to write dozens of Viruses...
-
Jul 19th, 2001, 03:13 PM
#9
Thread Starter
New Member
Hallelujah!!!!
Well, using two picture boxes was not quite what I had wanted to do, but as one of our apps guys here said, "Whatever works."
Thanks Fishcake, it really was as simple as setting the second pictureboxe's redraw property to true to blit from one to the other and back again.
And thanks for all your help Nirces - one day I'll come back and try to get the blitting to and from memory to work.
Thanks heaps peoples.
<- One happy chappy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|