-
getting image type
i m getting image properties from database
but this work is easy with if we load image from disk
but loading an image from data base then getting its properties is still dificult task.
this is the showproperties method which gets image from data base and shows its properties in a list view
Code:
Private Sub ShowProperties(ByVal item As TreeItem)
Try
' Create a command to select the selected photo
Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.Id)
Dim cmd As New SqlCommand(strCmd, SqlConn)
' Get bytes return from stored proc
Dim b As Byte() = CType(cmd.ExecuteScalar(), Byte())
If b.Length > 0 Then
' Open a stream for the image and write the bytes into it
Dim stream As New System.IO.MemoryStream(b)
Dim img As Image
img = Image.FromStream(stream)
listView1.Items.Clear()
listView1.Items.Add(New ListViewItem(New String() {"Type", GetImageTypeName(img.RawFormat)}))
listView1.Items.Add(New ListViewItem(New String() {"Resolution", img.Size.Height & " * " & img.Size.Width & " Pixels"}))
listView1.Items.Add(New ListViewItem(New String() {"Height", img.Height.ToString() & " Pixels"}))
listView1.Items.Add(New ListViewItem(New String() {"Width", img.Width.ToString() & " Pixels"}))
listView1.Items.Add(New ListViewItem(New String() {"Horizontal Resolution", img.HorizontalResolution.ToString() & " Pixels/Inch"}))
listView1.Items.Add(New ListViewItem(New String() {"Vertical Resolution", img.VerticalResolution.ToString() & " Pixels/Inch"}))
listView1.Items.Add(New ListViewItem(New String() {"Pixel Format", img.PixelFormat.ToString()}))
listView1.Items.Add(New ListViewItem(New String() {"Palette Flags", img.Palette.Flags.ToString()}))
listView1.Items.Add(New ListViewItem(New String() {"Raw Format", img.RawFormat.ToString}))
' Draw photo to scale of picturebox
DrawToScale(New Bitmap(stream))
' Close the stream and delete the temp file
stream.Close()
End If
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub
and second function is GetImageTypeName which is used for getting image data type
Code:
Private Function GetImageTypeName(ByRef ImageFormat As System.Drawing.Imaging.ImageFormat) As String
Dim sType As String
Select Case True
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "BMP"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "EMF"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "EXIF"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "GIF"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "ICON"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "JPEG"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "PNG"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "TIFF"
Case Object.Equals(System.Drawing.Imaging.ImageFormat.Bmp, ImageFormat)
sType = "WMF"
Case Else
sType = "UNKNOWN"
End Select
Return sType
End Function
but problem is that when i select an image its image type is displayed to "UNKNOWN"
and similarly i want to get image size
kindly tell me how can I get perfect image type and its size in KB ...thanks
-
Re: getting image type
Have you actually read your code? Every single one of your cases is testing for BMP, so everything that isn't a BMP will come back as unknown.