0

Question is how to differentiate this 2 image format if i were to drag an jpg image or gif image to inkcanvas? When i run it, i drag my gif image to the inkcanvas but it didnt went to the first condition. It went to the else if.

gif is declare on top as

Viewbox vbMedia = new Viewbox();    
MediaElement gif = new MediaElement();    
if (gif.Source == new Uri("E:\\New folder\\Drawing\\Images\\Themes\\Gif\\bruce.gif", UriKind.Absolute))
{
    vbMedia.Width = 70;
    vbMedia.Height = 70;

    gif.LoadedBehavior = MediaState.Play;
    gif.UnloadedBehavior = MediaState.Play;

    vbMedia.RenderTransform = group;                    
    vbMedia.Child = gif;

    this.InkCanvas1.Children.Add(vbMedia);        
}                
else                
{                    
    image.Width = 70;                  
    image.Height = 70;                    
    image.RenderTransform = group;

    this.InkCanvas1.Children.Add(image);        
}
Roel van Westerop
  • 1,400
  • 8
  • 17

1 Answers1

0

First of all, you always go in the else condition because you create your MediaElement gif the line before you check the gif.Source value. Thus at this moment it is always null, and you always go in the else condition.

Now for your question

how to differentiate this 2 image format?

I think this answer might help you : How can I know what image format I get from a stream? In your case it could be something like that:

    System.Drawing.Image image = System.Drawing.Image.FromFile("E:\\New folder\\Drawing\\Images\\Themes\\Gif\\bruce.gif");
    if (ImageFormat.Gif.Equals(image.RawFormat))
    {
        // GIF
    }
    else if (ImageFormat.Jpeg.Equals(image.RawFormat))
    {
        // JPEG
    }
Community
  • 1
  • 1
Ouarzy
  • 3,015
  • 1
  • 16
  • 19
  • Alright i will try, Another question is there a way to get all images from a specific folder? Let's say "Gif Folder" and there is 3 gif images inside. – NewbieCoder1993 Aug 22 '14 at 02:29