Hello guys!
This is probably a very dumb question, but I did not get any sleep the last couple of days..
I have 2 pictureboxes. In one picturebox I select an area with this code :
Now, I want to copy the selection into another picturebox. How can I do this ¿Code:Option Explicit Dim StartX As Single 'Starting X Position Dim StartY As Single 'Starting Y Position Dim EndX As Single 'Ending X Position Dim EndY As Single 'Ending Y Position Dim DrawBox As Boolean Private Sub Pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) pic.Cls 'Clear The Previous Box If Button = vbLeftButton Then 'If Left Is Pressed 'Store Coordinates StartX = X EndX = X StartY = Y EndY = Y DrawBox = False End If End Sub Private Sub Pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then 'If Left Button Is Pressed pic.DrawMode = vbInvert 'Invert The Line If DrawBox Then 'If pic.Line (StartX, StartY)-(EndX, EndY), , B End If pic.Line (StartX, StartY)-(X, Y), , B EndX = X EndY = Y DrawBox = True End If End Sub
I tried BitBlitting, but it did not produce any results. This is what I attempted :
But, Picturebox2 did not show anything. How can I copy only the selection on Picturebox1 to picturebox2 ¿Code:'APIs declarations omitted Private Sub Command1_Click() Dim hTmp As Long 'DC in memory Dim hBitmap As Long 'Bitmap to be associated with the DC 'Create a DC with the same settings as the picturebox hTmp = CreateCompatibleDC(pic.hdc) 'Do this. Also set the AutoRedraw of the Form to true Me.ScaleMode = vbPixels 'If the DC was created... If hTmp Then 'Obtain a bitmap with compatible settings hBitmap = CreateCompatibleBitmap(pic.hdc, pic.Width, pic.Height) If hBitmap Then 'associate this bitmap with the DC SelectObject hTmp, hBitmap 'Copy the picture from Picture1 on to the memory DC BitBlt hTmp, 0, 0, pic.Width, pic.Height, pic.hdc, 0, 0, vbSrcCopy 'Now copy it back to the Form BitBlt Pic2.hdc, 0, 0, pic.Width, pic.Height, hTmp, 0, 0, vbSrcCopy End If End If 'Remove these objects now DeleteObject hBitmap DeleteDC hTmp End Sub
Any help would be greatlt appreciated.





Reply With Quote