I am using the web browser control to generate screenshots of an intranet application developed in ASP.NET.
The screenshot is generated, compressed and then stored as a BLOB in the database. When I developed this facility I investigated the best way of compressing the image (to the lowest byte size), however the images still seem to be too big as the database table is growing larger than I hoped. I am using the TIFF format, but I am now thinking that this may not be the best as it is used by photographers (who I assume require good quality photographs). Here is the code to compress the image (before it is stored as a BLOB):
Public Function compressImage() As String
Try
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Tiff)
'Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
Dim myEncoderParameters As New EncoderParameters(1)
Dim myEncoderParameter As New EncoderParameter(System.Drawing.Imaging.Encoder.Compression, CLng(EncoderValue.CompressionCCITT3))
myEncoderParameters.Param(0) = myEncoderParameter
Dim ms As MemoryStream = New MemoryStream()
'bmp1.Save(ms, ImageFormat.Jpeg)
ConvertedImage.Save(ms, ImageFormat.Tiff)
Dim bmpBytes() As Byte
bmpBytes = ms.ToArray()
'ConvertedImage.Dispose()
ms.Close()
ms = Nothing
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Function
Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageDecoders()
Dim codec As ImageCodecInfo
For Each codec In codecs
If codec.FormatID = format.Guid Then
Return codec
End If
Next codec
Return Nothing
End Function
Is there a file format/compression algorithm I should use to try and make the file as small as possible without sacrifycing quality too much
Jpg or Png should get you smaller than Tiff.