|
-
Sep 19th, 2024, 06:05 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How can we APPROPRIATELY Size-Fit image into Picturebox ?
Hello
Any ideas how can we APPROPRIATELY Size-Fit image into Picturebox ?
Inorder to achieve above, Firstly I started exploring MS-Paint and was Zooming with MS-Paint's Zoom Track Bar at very bottom right corner of MS-Paint.
and was impressed by its Zoom Out (Enlarge) and Zoom In (Shrinking) although with fixed % View points for Zooming. 100% being at centre (Normal View of Image), 12.50% being at
extreme left (Smallest View) and 700% (Largest Point view).
On basis of above exploration, i thought of incorporating the similar concept of Image's size which is bigger than picturebox size.
with 12.50% Full image was seen, with 25% had to scroll up and Down a bit with 50% and above had to scroll left to Right, vice versa, Up and Down
My image Size is 3511 W with 4375 Height and PictureBox1 Size is 700 W 700H so in given scenario
how can I approximately fit with slightly enlarged zoom for readble fonts etc
Incorporated the below Function code from Simple-Proper-Image-Scaling
Code:
Public Class workingWithIamges
Private imgpath As String = "C:\Images\Img1.JPG"
Private Sub FormLayout()
Me.Location = New Point(0, 0) '
Me.Size = New Size(800, 800)
PictureBox1.Location = New Point(65, 5) '(100,5) '(86, 5)
PictureBox1.Visible = True '
PictureBox1.Size = New Size(700, 700)
'PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
'Call Option1()
'Call Option2()
Call Option3()
End Sub
Private Sub Option3()
PictureBox1.Image = ScaleImage(Image.FromFile(imgPath), PictureBox1.Height, PictureBox1.Width)
End Sub
Public Function ScaleImage(ByVal OldImage As Image, ByVal TargetHeight As Integer,_
ByVal TargetWidth As Integer) As System.Drawing.Image
Dim NewHeight As Integer = TargetHeight
Dim NewWidth As Integer = NewHeight / OldImage.Height * OldImage.Width
If NewWidth > TargetWidth Then
NewWidth = TargetWidth
NewHeight = NewWidth / OldImage.Width * OldImage.Height
End If
Return New Bitmap(OldImage, NewWidth, NewHeight)
End Function
When executed the above img in picturebox. Found bit Squarish dent because of Sqaure PictureBox
Any better option that it automatically takes the ratio like 12.5%, 25% etc. and as per the image size that it fits appropriately and represents accordingly.
Thanks
nkvb
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
|