Results 1 to 2 of 2

Thread: getting image type

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    87

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width