0

I am trying to make a program that will allow a user to view an icon in a PictureBox. I want the user to only be able to open images that are 24x24 pixels.

I would like to put a filter in an OpenFileDialog to only show images that are 24x24. Is there any way to do this? I heard that it may be possible by customizing the OpenFileDialog and using P/Invoke.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
Hunter Mitchell
  • 7,063
  • 18
  • 69
  • 116

3 Answers3

2

You could check the Width and Height of the image:

// 'image' is the image you want to check
if(image.Width > 24 || image.Height > 24)
    MessageBox.Show("Please select a smaller image!");
else
    // This code will always run if the image is smaller than 24x24

Hope this helps!

matthewr
  • 4,679
  • 5
  • 30
  • 40
0

If you're reading it in by storing it as an object (which I assume you are), you just need to read off imageObject.Width "using System.Drawing;" or "using System.Drawing.Image;"

examples here and here.

Community
  • 1
  • 1
impyre
  • 87
  • 7
  • in case you were wondering why you got downvotes, I can't speak for anyone else (including whoever voted), but I honestly didn't even know the answer myself. It took me less time to google "how to find an image's width" than it took you to write this question... a question which also mimics another question already posted here on stackoverflow. (for future reference) It's just that people expect that if you expect them to put effort into answering your question thoroughly, then you would accordingly put effort into answering it yourself first. (and most people expect you to show them you did) – impyre Jul 03 '12 at 23:11
0

You can't do this with the OpenFileDialog. You would need to write your own dialog that would interrogate the files in each folder and determine if they match your criteria and then show only those files.

Brian K. Carroll
  • 125
  • 1
  • 1
  • 4