Good evening,

Just want to ask if there's a way to get the contrast and pixeltype(if it's colored/bitonal/grayscale) of an existing image using vb .net such as: gif/jpg/pdf/png/tif
If yes, how?

Godbless and thanks in advance,
nel

Recommended Answers

All 5 Replies

You're probably looking for the Image class. Its PixelFormat property will tell you the pixel type.

As for contrast... Do you mean the image's dynamic range? That's something you'll have to calculate yourself from the image contents.

Yap, i did use that, "the image.PixelFormat", but for grayscale and bitonal this will just give same output..

dynamic range? is it the same with the contrast(DPI/dot per inch)?

for example:
Dim i As Image = Image.FromFile(strFilePath)
Dim lngScanType = i.PixelFormat

OUTPUT
colored: lngScanType = 137224
grayscale: lngScanType = 2498570
bitonal: lngScanType = 2498570

Bitonal: .NET doesn't distinguish 1-bit color... I guess you'll have to scan through the pixels and count colors, or find a library that will do it for you.

Contrast: There are multiple ways to define a contrast value. Dynamic range is a simpler, related measure.

The term bitonal often refers to 1-bit images that have specifically pure black and pure white colors. You can probably examine the colors of the image using the Image.Palette property to see if they meet this requirement.

About contrast, there's a post that explains one way of comparing contrast with a nice explanatory screenshot image here:
http://support.leadtools.com/CS/forums/42257/ShowPost.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.