This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Get Image Width and Height without loading the image

Hi,

I need a very fast way to know if an image is portrait or landscape or square.

My current version is loading the picture into size 80 thumbnail, and check on the orientation.


Dim thumbnail As New Aurigma.GraphicsMill.Bitmap
' Create appropriate format reader. 
Dim reader As Aurigma.GraphicsMill.Codecs.FormatReader = _
    Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader(FileName)
' LoadFrame returns a frame object. 
' From this frame we can get a thumbnail.
Dim frame As Aurigma.GraphicsMill.Codecs.Frame = reader.LoadFrame(0)
frame.GetThumbnail(thumbnail, 80, 0)
frame.Dispose()
reader.Dispose()
If thumbnail.Width > thumbnail.Height Then
    lLandscape = lLandscape + 1
ElseIf thumbnail.Height > thumbnail.Width Then
    lPortrait = lPortrait + 1
Else
   lSquare = lSquare + 1
End If
thumbnail.Dispose()


May I know is there any other better / faster way? It will be great if it don't even need to load the image.
Hello,

Yeap, of course - you can use IFrame.Width and IFrame.Height properties. They contain correct values independently of the IFrame.GetBitmap(...) method call.

I modified your sample a little to illustrate the way:

Aurigma.GraphicsMill.Codecs.IFormatReader reader = 
	Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader("x:/allformats/24bppRgb_Kite.jpg");

using (Aurigma.GraphicsMill.Codecs.IFrame frame = reader.LoadFrame(0))
{
	if (frame.Width > frame.Height)
	{
		//Landscape
	}
	else if (frame.Width < frame.Height)
	{
		//Portrait
	}
	else
	{
		//Square
	}
}

reader.Close();
reader.Dispose();