Ken Robertson's Blog

Ramblings of a .NET developer

Any way to check image type and get dimensions without System.Drawing?

Anyone know of any way to test the image type and get the width/height without using the System.Drawing namespace?  I'm working on a small app that processes a lot of pictures at once and could get multiple users using it at the same time.  When I use it without doing its image calculations, it only takes max 10% of the CPU.  However, when I have it get the width/height (which I need for it to work properly) using a bitmap, it gets up to around 80% CPU usage.  Big jump!

I'd found this java class that tests an image's type and gets the width/height by looking at its data raw, but alas, it is in Java, and converting it to .NET is too much of a pain (was trying it for a while... down to 29 errors that I know of).  When screwing around with some of the raw data, I can find the width/height in the file, but the offset it sometimes different, since it seems to depend on the size of a header that is before it.

Somebody somewhere in .NET Land must of thought of doing something like this before?

Posted: Dec 28 2004, 10:38 PM by qgyen | with 4 comment(s)
Filed under:

Comments

Robert Johnson said:

I use the Ambientware ImageUtil component (http://www.ambientware.com/components/imageUtil.aspx). It works great, is very fast and error free. (It also does a great job sizing pictures).
# December 29, 2004 2:38 AM

Stuart Ballard said:

You could try running IKVM (http://www.ikvm.net/) on the Java code to get CLR code out of it.

The only downside is that that pulls in a few pretty large DLLs that might bloat your app size.
# December 29, 2004 9:31 AM

Ken Robertson said:

I don't want to buy any utils, since this is for Telligent/Community Server, so it will be distributed and a site license wouldn't work. Also want it small and fast, so don't want to have to pull some big libraries or anything.

Last night I did manage to get the Java code converted over to C#. It wasn't as bad as I thought it would be. Also stripped out some stuff I wasn't going to need and checking for file types that CS doesn't support. Will probably email the author and ask permission to release the C# code.
# December 29, 2004 12:08 PM

Any way to check image type and get dimensions without System.Drawing? said:

Pingback from  Any way to check image type and get dimensions without System.Drawing?

# November 27, 2007 8:25 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)