I am using the simple code below to load and image from SQL, then save it back to the Image datatype column.
I am able to load the image, but when I perform ANY edit feature (from the RadImageEditor control) the size of the image (relative size on disk in bytes) increases over 10x the original image. Eventually it will consume all the memory and crash the application. This behavior does not happen if I load a fixed image directly from disk.
The two attached images show the size of the image after immediately loading it, then the size of the image after performing a single Rotate 90 degrees.
I cannot find any example of either loading an image from a DB nor saving to DB. Please review and provide any correction to loading and saving images (blob, image) from SQL, or please provide a simple example of loading and saving a SQL image.
FYI: objAttach.ImageBlob is defined as Byte()
Private Sub frmAttachmentViewer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.lblMessage.Text = ""
mbImageChanged = False
Dim ms As MemoryStream = New MemoryStream(objAttach.ImageBlob, 0, objAttach.ImageBlob.Length)
Dim img As Image = Image.FromStream(ms)
Me.RadImageEditor1.OpenImage(img)
lblImgSize.Text = "Size: " & ms.Length & " KB"
End Sub
Private Sub RadImageEditor1_CurrentImageChanged(sender As Object, e As ImageChangedEventArgs) Handles RadImageEditor1.CurrentImageChanged
Dim ms As New MemoryStream()
Me.RadImageEditor1.SaveImage(ms)
lblImgSize.Text = "Size: " & ms.Length & " KB"
End Sub
Dim ms As New MemoryStream()
Try
Me.RadImageEditor1.SaveImage(ms)
Dim iToInt As Integer = Convert.ToInt32(ms.Length)
Dim imgBinaryData As Byte() = New Byte(iToInt - 1) {}
imgBinaryData = ms.ToArray()
objAttach.ImageBlob = imgBinaryData
objAttach.save()
Me.lblMessage.Text = "Image Saved"
Catch ex As Exception
MessageBox.Show("Error Saving Image: " & vbCrLf & vbCrLf & ex.Message)
Finally
ms = Nothing
End Try
End Sub