开发者

Determining resolution (DPI) of an uploaded image

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 de开发者_StackOverflowcoder 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?


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.


Try F J core assemblies to find DPI of image in silverlight

FileStream stream = imageFiles.OpenRead();
DecodedJpeg jpegImage = new JpegDecoder(stream).Decode();
int imageDpi = jpegImage.Image.DensityX;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜