تقييم الموضوع :
  • 1 أصوات - بمعدل 5
  • 1
  • 2
  • 3
  • 4
  • 5
[مقال] Check the file format of an Image
#1
مقدمـــــــــة

منذ عامان أو أقل قليلا كتبت مقالا في المنتدي القديم عن كيفية التعامل مع الصور المتحركة...في هذه الوقت كنت أحتاج الي التأكد من نوعية الصورة و أنها من نوع GIF

لذلك كتبت دالتان من خلالهم نمرر أي صورة Image ..... و من ثم نسترجع قيمة عبارة من النوع Boolean

الدالة الأولي:

الهدف منها كان أن أتأكد من عدد Frames الموجودة في الصورة فإن كانت أكبر من العدد واحد (1) فهذا يؤكد أن الصورة من النوع المطلوب وهو GIF.
الكود ادناه يوضح شكل الدالة

كود :
''' <summary>Chech if Image is GIf animated image, using framacount</summary>
    ''' <param name="img">image to check</param>
    ''' <returns>Flag to indicate that the image passed to the function is of gif type</returns>
    ''' <remarks>if the image passed to the function is of gif type, the reurn value shall be true</remarks>
    Friend Shared Function IsGifImage(ByVal img As Image) As Boolean
        Return img IsNot Nothing AndAlso ((img.GetFrameCount(New FrameDimension(img.FrameDimensionsList(0)))) > 1)
    End Function


الدالة الثانية:

الهدف منها ايضا هو التأكد من RawFormat الخاصة بالصورة و انها من النوع GIF
الكود أدناه يوضح شكل الدالة
ملحوظة: هذه الكود يمكن التعديل به للتأكد من الانواع الاخري للصورة مثل bmp أو png او أي نوع أخر مماثل

كود :
''' <summary>Chech if Image is GIf animated image, using imageformat</summary>
    ''' <param name="img">image to check</param>
    ''' <returns>Flag to indicate that the image passed to the function is of gif type</returns>
    ''' <remarks>if the image passed to the function is of gif type, the reurn value shall be true</remarks>
    Friend Shared Function IsGifSupported(img As Image) As Boolean
        Return img IsNot Nothing AndAlso img.RawFormat.Guid = ImageFormat.Gif.Guid
    End Function


و منذ أيام و بعد مراجعة الدالتان أعلاه وجدت انه و من الأفضل ان يكون عندي دالة أقوي فقمت بدمج الدالتان معا في دالة واحدة
الكود أدناه يوضح شكل الدالة

الدالة الثالثة:

كود :
''' <summary>Chech if Image is GIf animated image, using bith frame count and image format</summary>
    ''' <param name="img">image to check</param>
    ''' <returns>Flag to indicate that the image passed to the function is of gif type</returns>
    ''' <remarks>if the image passed to the function is of gif type, the reurn value shall be true</remarks>
    Friend Shared Function IsAnimatedImage(img As Image) As Boolean
        Return img IsNot Nothing AndAlso img.RawFormat.Guid = ImageFormat.Gif.Guid AndAlso ((img.GetFrameCount(New FrameDimension(img.FrameDimensionsList(0)))) > 1)
    End Function

كيف تستخدم الكود:

الكود ادناه يوضح كيفية استخدام هذه الدوال من خلال الحدث Paint الخاص بالفورم

كود :
Dim bmp As Image = My.Resources.calypso_jpg
        If Not IsAnimatedImage(bmp) Then
            e.Graphics.DrawImage(bmp, 0, 0)
        End If


أتمني أن الكود يكون مفيدا لكم

تقبلوا تحياتي
الرد }}}
تم الشكر بواسطة: سعود , Sajad , الشاكي لله , Japan


الردود في هذا الموضوع
Check the file format of an Image - بواسطة silverlight - 15-05-14, 04:51 AM
RE: Check the file format of an Image - بواسطة vbnet - 15-05-14, 09:47 AM
RE: Check the file format of an Image - بواسطة silverlight - 15-05-14, 04:48 PM
RE: Check the file format of an Image - بواسطة Sajad - 28-05-14, 05:02 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم