|
| |||||||||
| Tags: dimension, image, image modification, photo, picture, vbnet |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Unable to change the dimension of image in VB.NET I am unable to change the dimension of an image with the following code: Code: Dim pictbox As New PictureBox
Dim img_url As String = Server.MapPath("~/uploads/" & code_url & "/") + System.IO.Path.GetFileName(fup.PostedFile.FileName)
Dim MyStream As FileStream = New FileStream(img_url, FileMode.Open)
pictbox.Image = Drawing.Image.FromStream(MyStream)
pictbox.SizeMode = PictureBoxSizeMode.StretchImage
Dim height As Integer
Dim width As Integer
Dim W As Integer
Dim H As Integer
Dim coef As Double
height = pictbox.Image.Height
width = pictbox.Image.Width
pictbox.Height = H
pictbox.Width = W
pictbox.Update()
Try
If type_file = ".png" Then
pictbox.Image.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Png)
ElseIf type_file = ".jpg" Or type_file = ".jpeg" Then
pictbox.Image.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Jpeg)
ElseIf type_file = ".gif" Then
pictbox.Image.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Gif)
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
MyStream.Close()
Return True |
|
#2
| |||
| |||
| Re: Unable to change the dimension of image in VB.NET
Normally to resizing an image is a bit more complicated Code: dim ImgRedimension as new bitmap(newWidth, newHeight) dim g as graphics = graphics.fromimage(ImgRedimension) g.Drawimage(image_of_base, divers_parameters) ImgRedimension.save() |
|
#3
| |||
| |||
| Re: Unable to change the dimension of image in VB.NET
Hello, thank you for your answer, being that second year can you explain a little more simply please? Because I do not know what to do with graphics. Instead of pictbox.image.save I must put graphic.save? I do not see what you mean by source rectangle etc. |
|
#4
| |||
| |||
| Re: Unable to change the dimension of image in VB.NET
I've put almost all the code to resize an image, you must create a new dimension for the new, create graphics associated with this new image drawing the basic image we have on the graphics with the new size then the image created can be saved DrawImage has 30 overloads, one must use an application that SrcRect and DestRect (just read the intellisense) and Code: dim srcrect as new rectangle (0,0,picturebox.image.width,picturebox.image.height) dim destcrect as new rectangle (0,0,newWidth,newHeight) |
|
#5
| |||
| |||
| Re: Unable to change the dimension of image in VB.NET Code: Dim ImgRedimension As New Bitmap(W, H)
Dim g As Graphics = Graphics.FromImage(ImgRedimension)
g.DrawImage(pictbox.Image, pictbox.DisplayRectangle.Location)
Try
If type_file = ".png" Then
ImgRedimension.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Png)
ElseIf type_file = ".jpg" Or type_file = ".jpeg" Then
ImgRedimension.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Jpeg)
ElseIf type_file = ".gif" Then
ImgRedimension.Save(Server.MapPath("~/uploads/" & code_url & "/") + name_vig_file, Imaging.ImageFormat.Gif)
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try |
|
#6
| |||
| |||
| Re: Unable to change the dimension of image in VB.NET Code: Dim imageFinal As System.Drawing.Image = Nothing Dim g As System.Drawing.Graphics = Nothing imageFinal = New System.Drawing.Bitmap(new_size.Width, new_size.Height) g = System.Drawing.Graphics.FromImage(imageFinal) Dim destRect As New System.Drawing.Rectangle(0, 0, new_size.Width, new_size.Height) Dim srcRect As New System.Drawing.Rectangle(0, 0, IMG.Width, IMG.Height) g.DrawImage(IMG, destRect, srcRect, System.Drawing.GraphicsUnit.Pixel) imageFinal.save(...) |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Unable to change the dimension of image in VB.NET" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unable to detect memory in Dell dimension | Tana$ya | Motherboard Processor & RAM | 6 | 03-07-2011 11:29 AM |
| Unable to upgrade Dell Dimension B110 CPU | Kim|ball | Motherboard Processor & RAM | 4 | 03-06-2011 11:34 AM |
| Unable to pass post in Dimension E310 | Virr | Hardware Peripherals | 6 | 01-06-2011 11:11 PM |
| Unable to get any sound in Dell dimension 4700c | The^Affleck | Hardware Peripherals | 5 | 21-04-2011 07:20 PM |
| Unable to get audio in Dimension 4700 | Dechen | Portable Devices | 4 | 21-02-2011 07:43 PM |