|
-
Sep 18th, 2006, 03:57 AM
#1
Thread Starter
Lively Member
Run Time Image Resizing
hi,
I have prepared a vb application in which i have got a scan command button.
As i press "Scan" button the document in the scanner gets scanned and is visible on the image area or picture area defined by me on the form. This part is working perfectly fine.
My problem is, the area defined in the form for scanned image is very small, as there are other input fields. For example the image area on the form is 1300 X 1400, and the image which i scanned is around 4000X 3000.
Can i resize the image in run time, so that the whole image appears in the area defined by me.
I am using VS TWAIN Code for scanning feature.
Regards,
Kaushik
-
Sep 18th, 2006, 04:16 AM
#2
Re: Run Time Image Resizing
If you want to add a picture in a Picturebox or in the form using the control's size, you can do it using PaintPicture.
Using a PictureBox, you can do it like this:
VB Code:
Private Sub Form_Load()
Dim lPic As Picture
Me.Picture1.AutoRedraw = True
Set lPic = LoadPicture("C:\YourPicture.jpg") 'Use the correct path and filename here
ResizePicture Me.Picture1, lPic
End Sub
Private Sub ResizePicture(pBox As PictureBox, pPic As Picture)
Dim lWidth As Single, lHeight As Single
Dim lnewWidth As Single, lnewHeight As Single
'Clear the Picture in the PictureBox
pBox.Picture = Nothing
'Clear the Image in the Picturebox
pBox.Cls
'Get the size of the Image, but in the same Scale than the scale used by the PictureBox
lWidth = pBox.ScaleX(pPic.Width, vbHimetric, pBox.ScaleMode)
lHeight = pBox.ScaleY(pPic.Height, vbHimetric, pBox.ScaleMode)
'If image Width > pictureBox Width, resize Width
If lWidth > pBox.ScaleWidth Then
lnewWidth = pBox.ScaleWidth 'new Width = PB width
lHeight = lHeight * (lnewWidth / lWidth) 'Risize Height keeping proportions
Else
lnewWidth = lWidth 'If not, keep the original Width value
End If
'If the image Height > The pictureBox Height, resize Height
If lHeight > pBox.ScaleHeight Then
lnewHeight = pBox.ScaleHeight 'new Height = PB Height
lnewWidth = lnewWidth * (lnewHeight / lHeight) 'Risize Width keeping proportions
Else
lnewHeight = lHeight 'If not, use the same value
End If
'add resized and centered to Picturebox
pBox.PaintPicture pPic, (pBox.ScaleWidth - lnewWidth) / 2, _
(pBox.ScaleHeight - lnewHeight) / 2, _
lnewWidth, lnewHeight
'Update the Picture with the new image if you need it
Set pBox.Picture = pBox.Image
End Sub
You can add ResizePicture sub in a module (declare it Public) if you want.
The VB.NET version is here.
Last edited by jcis; Jan 13th, 2007 at 09:40 PM.
-
Sep 20th, 2006, 03:47 AM
#3
Thread Starter
Lively Member
Re: Run Time Image Resizing
 Originally Posted by jcis
If you want to add that resized picture in a Picturebox or in the form, you can use PaintPicture.
Using a PictureBox, you can do it like this:
VB Code:
Private Sub Form_Load()
Dim lPic As Picture
Me.Picture1.AutoRedraw = True
Set lPic = LoadPicture("C:\YourPicture.jpg") 'Use the correct path and filename here
ResizePicture Me.Picture1, lPic
End Sub
Private Sub ResizePicture(pBox As PictureBox, pPic As Picture)
Dim lWidth As Single, lHeight As Single
Dim lnewWidth As Single, lnewHeight As Single
'Clear the Picture in the PictureBox
pBox.Picture = Nothing
'Clear the Image in the Picturebox
pBox.Cls
'Get the size of the Image, but in the same Scale than the scale used by the PictureBox
lWidth = pBox.ScaleX(pPic.Width, vbHimetric, pBox.ScaleMode)
lHeight = pBox.ScaleY(pPic.Height, vbHimetric, pBox.ScaleMode)
'If image Width > pictureBox Width, resize Width
If lWidth > pBox.ScaleWidth Then
lnewWidth = pBox.ScaleWidth 'new Width = PB width
lHeight = lHeight * (lnewWidth / lWidth) 'Risize Height keeping proportions
Else
lnewWidth = lWidth 'If not, keep the original Width value
End If
'If the image Height > The pictureBox Height, resize Height
If lHeight > pBox.ScaleHeight Then
lnewHeight = pBox.ScaleHeight 'new Height = PB Height
lnewWidth = lnewWidth * (lnewHeight / lHeight) 'Risize Width keeping proportions
Else
lnewHeight = lHeight 'If not, use the same value
End If
'add resized and centered to Picturebox
pBox.PaintPicture pPic, (pBox.ScaleWidth - lnewWidth) / 2, _
(pBox.ScaleHeight - lnewHeight) / 2, _
lnewWidth, lnewHeight
'Update the Picture with the new image if you need it
Set pBox.Picture = pBox.Image
End Sub
You can add ResizePicture sub in a module (declare it Public) if you want.
Thanks man i will try it out. Sorry for replying a little late
Regards,
Kaushik
-
Sep 20th, 2006, 04:31 AM
#4
New Member
Re: Run Time Image Resizing
VB Code:
Private Sub Form_Load()
Image1.Width = Screen.Width
image1.Stretch = true
End Sub
Whatever you give, that's you will get

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
|