How do I get the resolution?

Vote:
 

Is there a way to get the resolution for an image? I'm using ImageVault 4.4 for the first time and couldn't find this specified anywhere in the documentation.

Cheers,

Annelie

#87037
Jun 08, 2014 18:39
Vote:
 

On the WebMedia class you can find a Width and Height property.

Read more about WebMedia on http://imagevault.se/en/documentation/api-documentation/?page=csharp/examples/get-item/webmedia.html

#87038
Jun 08, 2014 22:58
Vote:
 

Yes, I have the width and height but was wondering if I could get the resolution. In a previous version of ImageVault it was available on the IVFileData class. When you create an ImageFormat you can specify the Dpi, but I wasn't sure how to get it from an existing image.

#87040
Jun 09, 2014 9:51
Vote:
 

If you are interested in the original media pixel size you can query the ImageWidth and ImageHeight metadata.

The example below shows two examples to collect the metadata. Either by specifying what metadata to retrieve using the direct model.

The second example uses a declarative method using a class that declares the metadata to collect.

[Test]
public void GetWidthHeightMetadataTest() {
    var client = ClientFactory.GetSdkClient();
    var media = client.Query<MediaItem>()
        .Include(m => m.Metadata.Where(i => i.DefinitionType == MetadataDefinitionTypes.System && i.Name==SystemMetadata.ImageWidth))
        .Include(m => m.Metadata.Where(i => i.DefinitionType == MetadataDefinitionTypes.System && i.Name == SystemMetadata.ImageHeight))
        .ToList();
    foreach (var mediaItem in media) {
        var w = mediaItem.Metadata.FirstOrDefault(m => m.Name == SystemMetadata.ImageWidth);
        var h = mediaItem.Metadata.FirstOrDefault(m => m.Name == SystemMetadata.ImageHeight);
        Console.WriteLine(@"Id:{0},Width:{1},Height:{2}",mediaItem.Id,(w==null?"null":w.Value),(h==null?"null":h.Value));
    }
 
    var media2 = client.Query<MyMedia>().ToList();
    foreach (var myMedia in media2) {
        Console.WriteLine(@"Id:{0},Width:{1},Height:{2}", myMedia.Id, myMedia.Width, myMedia.Height);
    }
}
 
public class MyMedia : MediaItem {
    [Metadata(SystemMetadata.ImageWidth,Type= MetadataDefinitionTypes.System)]
    public int? Width { get; set; }
    [Metadata(SystemMetadata.ImageHeight, Type = MetadataDefinitionTypes.System)]
    public int? Height { get; set; }
}
#87042
Jun 09, 2014 10:48
Vote:
 

The Dpi is mostly relevant for printing an image and reflects how large the image will be (depending on the pixel size) on the output in inches.

When printing you can change the output dpi by specifying the width/height of the resulting printout thereby overriding the dpi information in the image.

Often the pixel size is more useful than the Dpi. 

What do you need the Dpi for?

#87043
Jun 09, 2014 11:03
Vote:
 

Dan, you are absolutely correct. The reason I need it is because our client has a website build with EPi 6 and ImageVault 3.5 where they display a list of the images in a specified vault and write out the Dpi (as well as the calculated width and height in millimeters), and they now want the same functionality for another one of their sites built with Epi 7 and ImageVault 4.4. It's more of a guide to say "if you print this image with this Dpi the width and height in millimeters will be x and y" if you see what I mean.

I wasn't sure how the Resolution value on the IVFileData class in ImageVault 3.5 was set, but I thought perhaps there was some logic behind it (i.e. if an image is smaller than a certain size set the Dpi to say 150 instead of 300 so people will know they need to have a lower quality to get a decent sized image). And if there were any logic behind it, and the property was available in ImageVault 4.4 as well, I didn't want to reinvent the wheel and write my own. :) 

I'll just use 300 dpi as a default and calculate the millimeters from there.

#87044
Jun 09, 2014 11:28
Vote:
 

Well we have no specific logic around the dpi value. It's only kept as an option if you would like to store a specific dpi setting in the format you convert to. If it's possible we set it in the output media.

I think your workaround is a good choice when it comes to your clients needs.

#87045
Jun 09, 2014 11:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.