我在使用 vb.net 保存到 blob 数据类型之前重新调整图像大小时遇到问题。我不知道如何调整图像大小。
这是我的插入代码:
Dim FileSize As UInt32
Dim mstream As New System.IO.MemoryStream()
pic_box_save.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = mstream.GetBuffer()
FileSize = mstream.Length
mstream.Close()
MsgBox(FileSize)
Try
sql = "INSERT INTO clientreports(report_id, img) VALUES(@image_id, @image_data)"
sql_command = New MySqlCommand(SQL, sql_connection)
sql_command.Parameters.AddWithValue("@image_id", Nothing)
sql_command.Parameters.AddWithValue("@image_data", arrImage)
sql_command.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
MsgBox("Image has been saved.")
如果有人知道如何解决这个问题,请帮助我。谢谢!
最佳答案
要创建缩略图/调整图像大小:
Friend Function GetImageThumb(ByVal orgBmp As BitMap,
ByVal w as Int32, h as Int32) As Bitmap
Dim thumb As New Bitmap(w, h)
Using g As Graphics = Graphics.FromImage(thumb)
g.DrawImage(orgBmp , 0, 0, w + 1, h + 1)
End Using
Return thumb
End Function
对于数据存储,您可能需要将图像转换为其他内容,例如 Base64 字符串或字节数组。
关于mysql - 如何在保存到数据库之前调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21671668/