MicahCarrick
Jan 10th, 2000, 12:45 AM
Anyone know how I could clip out a rectangle area of a bitmap and display it in an image control?
------------------
Micah Carrick
http://micah.carrick.com
micah@carrick.com
ICQ: 53480225
Aaron Young
Jan 10th, 2000, 01:06 AM
Here's an example which lets you drag a rectangle around an area in a Picture and it copies that section to a new Picturebox:
Add 2 Pictureboxes to a Form, load the Picture to Select from in Picture1..
Private oX As Integer
Private oY As Integer
Private lX As Integer
Private lY As Integer
Private Sub Form_Load()
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
With Picture1
.DrawMode = vbInvert
oX = X
oY = Y
lX = oX
lY = oY
End With
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Picture1.Line (oX, oY)-Step(lX - oX, lY - oY), , B
Picture1.Line (oX, oY)-Step(X - oX, Y - oY), , B
lX = X
lY = Y
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim iTmp As Integer
Dim iW As Integer
Dim iH As Integer
If Button = vbLeftButton Then
Picture1.Line (oX, oY)-Step(lX - oX, lY - oY), , B
Picture2.Cls
If X < oX Then
iTmp = oX
oX = X
X = iTmp
End If
If Y < oY Then
iTmp = oY
oY = Y
Y = iTmp
End If
If X = oX Then X = 1
If Y = oY Then Y = 1
iW = X - oX
iH = Y - oY
Picture2.Width = ScaleX(iW, vbPixels, vbTwips)
Picture2.Height = ScaleY(iH, vbPixels, vbTwips)
Picture2.PaintPicture Picture1.Image, 0, 0, iW, iH, oX, oY, iW, iH
End If
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
MicahCarrick
Jan 10th, 2000, 01:21 AM
Thank you ... that'll work perfect. :)