views:

37

answers:

1

I have a component for an image file upload.

However, I want to also be able to check DPI settings because these images will eventually be printed and submitted on paper.

Within ASP.net, I can usually do something like this:

using (var rawBitmap = new Bitmap(postedFile.InputStream)){
    var dpi = (decimal)rawBitmap.VerticalResolution/bitmap.Height;    
    // do other stuff.
}

However, within silverlight, I don't have access to the same libraries in order to do this (that said, this is my first stab at Silverlight, so if there is a way to get those dlls in, I'm all for it, but I couldn't get my utility wrapper imported).

I've seen lots of recommendations for FJcore (imagetools also wraps this library), a JPEG encoding/decoding utility. In theory, one loads up the JPEG stream into the decoder and gets information out.

I've tried using the approach with FJcore, but all the files that I'm saving out of photoshop seem to be missing the correct header that indicates the star of the file, which causes the decoder to fail. I've also confirmed this issue using their unit tests.

Any ideas on how to pull image resolution out of a file upload in silverlight?

+3  A: 

DPI of the image is not always stored on the image. This is usually an extra property saved as a metadata during capture by the scanner (or the camera). You can actually see that if you load a JPEG in C# using Bitmap and save it again, DPI property is lost and set to the default 96.

So this is unfortunately not an option always reliable. I do not think there is any chance of getting it for all images. DPI in fact is irrelevant for pictures that are not created by scanners.

Aliostad
[EXIF](http://en.wikipedia.org/wiki/Exchangeable_image_file_format) is often used by digital cameras. Unfortunately, it is basically only supported for JPEG and TIFF images :( There are some links from the wiki page for some other formats. YMMV and have fun. I'm not entirely such what DPI has in a camera sense though :-)
pst
I had thought it was odd that bitmaps would even have a DPI property, good to have that cleared up. In our case, preserving the DPI isn't really important, but extracting print size is. Was hoping for another library for parsing the meta info, but I guess it's just the way it is.
ddango
Exactly. DPI is device context dependent but for cameras is meaningless.
Aliostad