Ever wonder how to imitate the Image control property stretch in vb6? This piece of code will do the trick... - Public Sub AutosizeImage(ByVal ImagePath As String, ByVal picBox As PictureBox, Optional ByVal pSizeMode As PictureBoxSizeMode = PictureBoxSizeMode.CenterImage)
-
Try
-
picBox.Image = Nothing
-
picBox.SizeMode = pSizeMode
-
If System.IO.File.Exists(ImagePath) Then
-
Dim imgOrg As Bitmap
-
Dim imgShow As Bitmap
-
Dim g As Graphics
-
Dim divideBy, divideByH, divideByW As Double
-
imgOrg = DirectCast(Bitmap.FromFile(ImagePath), Bitmap)
-
-
divideByW = imgOrg.Width / picBox.Width
-
divideByH = imgOrg.Height / picBox.Height
-
If divideByW > 1 Or divideByH > 1 Then
-
If divideByW > divideByH Then
-
divideBy = divideByW
-
Else
-
divideBy = divideByH
-
End If
-
-
imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy))
-
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
-
g = Graphics.FromImage(imgShow)
-
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
-
g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
-
g.Dispose()
-
Else
-
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
-
imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
-
g = Graphics.FromImage(imgShow)
-
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
-
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
-
g.Dispose()
-
End If
-
imgOrg.Dispose()
-
-
picBox.Image = imgShow
-
Else
-
picBox.Image = Nothing
-
End If
-
-
-
Catch ex As Exception
-
MsgBox(ex.ToString)
-
End Try
-
-
End Sub
-
====== To use this...=======
first copy the code in a module or somewhere else in your project then... -
AutosizeImage(Trim('" Image file path "'), '" picture control here "', PictureBoxSizeMode.StretchImage)
-
There you have it... :D
0 6774 Sign in to post your reply or Sign up for a free account.
Similar topics
by: hem |
last post by:
in my web application, i want to show dynamic images at
runtime with crystal report.net.
the image is residing in my local computer, i am having
problem at runtime i.e. how i give the image path...
|
by: bill.. |
last post by:
I have created a VB app that generates a wireless network status map
several times a day.
The app adds hidden controls in specific areas of the image (on a
form) with extra info in the tooltips...
|
by: Lumpierbritches |
last post by:
Thank you in advance for any and all assistance. I'm trying to make it where at
runtime my program will allow the introduction of an image.
I've tried bound, unbound and images. On the bound OLE...
|
by: dcudev.lcr |
last post by:
I am loading a 4X5 picturebox matrix using a bitmap file template. As each
cell in the matrix is being loaded, I append a text string using the
DrawString function to complete the cell's image.
...
|
by: Thomasa Gregg |
last post by:
I have a map that I want to add a pushpin image for each location I have in
a database. How do I go about adding the pushpin image to the x, y
coordinates I have calculated to the map image. I am...
|
by: Tyrant Mikey |
last post by:
I ahve a page that contains a DataGrid control that is offset from the
left-hand side of the page by about 100 pixels. What I want to do is
stretch the DataGrid to fill the remainder of the page...
|
by: Adam Maltby |
last post by:
Hi,
I am adding an new picbox and animated gif to it at runtime
Dim img As Image = Image.FromFile(Application.StartupPath & "\animation.gif")
With pic_Wait
.Location = New Point(300, 250)...
|
by: Asking |
last post by:
hi all,
I use TXTextControl (or RichTextBox). I inserted an image on it at runtime
and I want to draw some shapes on the image at runtime.
How can I do that? (it's windows application)
...
|
by: kulkanuja |
last post by:
i am using image control in asp.net in c# now i want to display binary(format) image from database to image control.
how do i do iot pls help.
|
by: Jeff Ciaccio |
last post by:
I am programming a "craps table", and I would like to randomize where the
dice land.
The first one is no problem. To fit on the "table" I have the following:
picDie1.Location = New Point(Rnd() *...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |