查询问题在FileUpload控件中保存调整后的图像 [英] query problem saving the adjusted image in a FileUpload Control
问题描述
我有一个参赛表格礼物请求用户必须在FileUpload1中输入一张照片图片
这个我的代码记录图片工作
I have a entry form gift requests the user must enter a photograph in the FileUpload1 up image
this my code to record the image works
Dim data As New vsolicitud
Insert Dim As New Fsolicitud
'Assign the image
Then if FileUpload1.HasFile
Using reader As New BinaryReader (FileUpload1.PostedFile.InputStream)
Dim image As Byte () = reader.ReadBytes (FileUpload1.PostedFile.ContentLength)
datos._nombre = FileUpload1.FileName
datos._length = FileUpload1.PostedFile.ContentLength
datos._numsolicitud = TxtNumSolicitud.Text
datos._imagen = image
insertar.GuardarImagen (data)
end if
然后我开始在互联网上搜索一个代码,pirmitira me culquier减少代码大小我在网上找到的图片选择任何图像并放置一定大小并保存具有该网站的文件夹
我的问题是这个代码存储在一个文件夹中以显示图像
因为我需要添加我的代码来记录图像上升
我打算显示图像然后记录这段代码
Then I started searching the internet a code that pirmitira me culquier reduce code size image I found on the internet select any image and put certain size and saves folder that has the site
my problem is that this code is stored in a folder to display the image
as I need to add my code to record the image rise
what I intend to display the image and then record this code
Protected Sub Button4_Click1 (sender As Object, e As EventArgs) Handles Button4.Click
Const bmpW = 300 'wide canvas New Picture
Const BMPH = 226 'tall canvas New Picture
If (FileUpload1.HasFile) Then
lblMensaje.Text = ""
'Make sure the uploaded file has a format image file extension
If (CheckFileType (FileUpload1.FileName)) Then
NewWidth Dim As Integer = bmpW
NewHeight Dim As Integer = BMPH
'Use the filename uploaded without the'. 'Extension
UPNAME Dim As String = Mid (FileUpload1.FileName, 1, (InStr (FileUpload1.FileName, ".") - 1))
Dim filePath As String = "~ / Images /" & UPNAME & ".png"
'Create a new bitmap using the image as a stream uploaded
'Set the new resolution bitmap 72 pixels per inch
Dim upBmp As Bitmap = Bitmap.FromStream (FileUpload1.PostedFile.InputStream)
Dim newBmp As Bitmap = new Bitmap (newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb)
newBmp.SetResolution (72, 72)
'Get the width and height of uploaded image
UpWidth Dim As Integer = upBmp.Width
UpHeight Dim As Integer = upBmp.Height
NewX Dim As Integer = 0
Newy Dim As Integer = 0
As Decimal Dim reduced
'Keep the aspect ratio of the image of the same if not 4: 3 and develop positions newX and Newy
'To ensure the image is always in the center of the vertical and horizontal fabric
If upWidth> upHeight Then 'Landscape image
Reduces = newWidth / upWidth 'calculate the percentage reduction in width and decimal
newHeight = Int (* Reduces upHeight) 'reduce the height of the image uploaded by reducing the amount
newy = Int ((BMPH - newHeight) / 2) 'the position of the image down in the center of the canvas
newX = 0 'will be wide
UpWidth ElseIf <upheight then="Portrait picture<br mode="hold" /><br mode="hold" /> Reduces = newHeight / upHeight " calculate="" the="" percentage="" reduction="" in="" height="" and="" mode="hold" /> newWidth = Int (* Reduces upWidth) 'reduce the height of the image uploaded by reducing the amount
newX = Int ((bmpW - newWidth) / 2) 'the position of the image in the center across the canvas
newy = 0 'image will be full
ElseIf upWidth = upHeight Then 'Square Photo
Reduces = newHeight / upHeight 'calculate the percentage reduction in height and decimal
newWidth = Int (* Reduces upWidth) 'reduce the height of the image uploaded by reducing the amount
newX = Int ((bmpW - newWidth) / 2) 'the position of the image in the center across the canvas
newy = Int ((BMPH - newHeight) / 2) 'the position of the image down in the center of the canvas
End If
'Create a new image of the loaded image using the Graphics class
'Clear the graph and set the background color to white
'Antialiasing and high quality bicubic use to maintain good image quality
'Save the new raster graphics using' PNG image format 'and the calculated positioning Canvas
Dim newGraphic As Graphics = Graphics.FromImage (newBmp)
Try
newGraphic.Clear (Color.White)
newGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
newGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
newGraphic.DrawImage (upBmp, newX, newy, newWidth, newHeight)
newBmp.Save (MapPath (filePath) Imaging.ImageFormat.Png)
'Show the image I uploaded the resized image control
imgSubida.ImageUrl = filePath
imgSubida.Visible = True
Catch ex As Exception
lblMensaje.Text = ex.ToString
Finally
upBmp.Dispose ()
newBmp.Dispose ()
newGraphic.Dispose ()
End Try
Else
lblMensaje.Text = "Please select an image with an extension format of BMP, JPG, JPEG, GIF or PNG file."
End If
End If
End Sub
CheckFileType Function (ByVal fileName As String) As Boolean
As String Dim ext = Path.GetExtension (filename)
Select Case ext.ToLower ()
Case ".gif"
Return True
Case ".png"
Return True
Case ".jpg"
Return True
Case ".jpeg"
Return True
Case ".bmp"
Return True
Case Else
Return False
End Select
End Function
End Class
推荐答案
或者......你可以使用 Image.GetThumbnailImage [ ^ ] - 回调只需返回 false
,因为它不再被调用。
Or...you could just use Image.GetThumbnailImage[^] - the callback just needs to return false
as it's not called any longer.
这篇关于查询问题在FileUpload控件中保存调整后的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!