15-05-14, 09:47 AM
-
في الزيادة إفادة.....
منقول
دالة GetImageFormat لتحديد نوع الصورة ( BMP, GIF, JPEG, PNG, TIFF, ICON, GIF animation )
طريقة استخدامها
في الزيادة إفادة.....
منقول
دالة GetImageFormat لتحديد نوع الصورة ( BMP, GIF, JPEG, PNG, TIFF, ICON, GIF animation )
كود :
' دالة تحديد نوع الصورة ( BMP, GIF, JPEG, PNG, TIFF, ICON, GIF animation )
Private Function GetImageFormat(ByVal img As Image) As String
Dim imgFormat As String = "Unknown"
If img.RawFormat.Guid = Imaging.ImageFormat.Bmp.Guid Then imgFormat = "BMP"
If img.RawFormat.Guid = Imaging.ImageFormat.Gif.Guid Then imgFormat = "GIF"
If img.RawFormat.Guid = Imaging.ImageFormat.Jpeg.Guid Then imgFormat = "JPEG"
If img.RawFormat.Guid = Imaging.ImageFormat.Png.Guid Then imgFormat = "PNG"
If img.RawFormat.Guid = Imaging.ImageFormat.Tiff.Guid Then imgFormat = "TIFF"
If img.RawFormat.Guid = Imaging.ImageFormat.Icon.Guid Then imgFormat = "ICON"
If imgFormat = "GIF" AndAlso img.GetFrameCount(Imaging.FrameDimension.Time) > 1 Then imgFormat = "GIF animation"
Return imgFormat
End Functionطريقة استخدامها
كود :
' (صورة من ملف (حتى لو تم تغيير النوع من اسم الملف
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using op As New OpenFileDialog()
op.Filter = "Images (*.bmp,*.gif,*.jpg,*.png,*.tif,*.ico)|*.bmp;*.gif;*.jpg;*.png;*.tif;*.ico"
If op.ShowDialog = DialogResult.OK Then
MsgBox(GetImageFormat(Image.FromFile(op.FileName)))
End If
End Using
End Subكود :
' صورة من الريسورس
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
MsgBox(GetImageFormat(My.Resources.logo))
End Sub


