Public Function createThumbandFull(ByVal ItemCode As String) As AUErrorCapture Implements IAUDBInUpDel.createThumbandFull
Dim errorReturn As AUErrorCapture = Nothing
Try
Dim db As New databaseLinqDataContext
db.Connection.ConnectionString =
furConn.ConnectionString
Dim itemIm = From i In db.AUOrigImages _
Where i.ItemCode = ItemCode _
Select i.ImageContent
Dim newResizedImage As Byte() = Nothing
Dim stream As MemoryStream
For Each retI In itemIm
newResizedImage = retI.ToArray
stream = New MemoryStream(newResizedImage)
ResizeThumbImage(CDbl(0.1), stream, ItemCode)
Next
Catch ex As Exception
Throw ex
End Try
Return errorReturn
End Function
Private Sub ResizeThumbImage(ByVal scaleFactor As Double, ByVal Filetoresize As MemoryStream, ByVal itemCodetoSave As String)
Try
Dim image__1 = System.Drawing.Image.FromStream(Filetoresize)
Dim newWidth = CInt((image__1.Width * scaleFactor))
Dim newHeight = CInt((image__1.Height * scaleFactor))
Dim thumbnailBitmap = New System.Drawing.Bitmap(newWidth, newHeight)
Dim thumbnailGraph = System.Drawing.Graphics.FromImage(thumbnailBitmap)
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic
Dim imageRectangle = New System.Drawing.Rectangle(0, 0, newWidth, newHeight)
thumbnailGraph.DrawImage(image__1, imageRectangle)
'Encoding Parameters
Dim quality As Integer = 90 '90 is the magic setting - really. It has excellent quality and file size.
Dim encoderParameters As New System.Drawing.Imaging.EncoderParameters(1)
encoderParameters.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CLng(quality))
Dim fs As System.IO.MemoryStream = New System.IO.MemoryStream()
thumbnailBitmap.Save(fs, image__1.RawFormat)
Dim img As Byte() = New Byte(fs.Length) {}
Dim db As New databaseLinqDataContext
db.Connection.ConnectionString =
furConn.ConnectionString
db.AUResizeThumbImage(itemCodetoSave, itemCodetoSave & ".jpg", img)
thumbnailGraph.Dispose()
thumbnailBitmap.Dispose()
image__1.Dispose()
Catch ex As Exception
Throw ex
End Try
End Sub
|