Click to See Complete Forum and Search --> : Problem displaying tiff with gdiplus


Chechu
April 18th, 2008, 01:33 PM
Hi, I have found a problem displaying some tiff images using gdiplus.dll functions. I obtain first the image´s size using methods GetHeight and GetWidth of Image class. I obtain too the heigth and width of screen using GetSystemMetrics function. With both I get the value for displaying the image in the middle of screen. This method works correctly for jpeg, bmp, gif formats and for some tiff format images. But in others tiff format images it seems the value os height and width of image is not according with screen coordinates (I checked that I need multiply by 1.3 aproximately for these coordinates fix).

For example:

// Screen dimensions
xScr = GetSystemMetrics(SM_CXSCREEN);
yScr = GetSystemMetrics(SM_CYSCREEN);

// Image dimensions
image = new Image(swzPath);
LengthImage=image->GetHeight();
WidthImage = image->GetWidth();

// Displaying
Graphics graphics(hdc);
iPosHor = (xScr-WidthImage)/2;
iPosVer = (yScr-LenghtImage)/2;
graphics.DrawImage(image, iPosHor, iPosVer);

with file pr2plus.tif works correctly, but with file imagen500.tif or imagen.tif you need multiply LengthImage and WidthImage for displaying image in the middle.

Is there another parameter that I must consider for displaying?

I attached cpp code, exe, and tif files for testing.

Thanks.

Chechu
April 22nd, 2008, 02:57 AM
I've fix it!. The problem is that is necessary to do a small conversion between the coordinates obtained with GetHeight and GetWidth and the real size in coordinates related to the window. The conversion is:

// Obtains resolution
resHor = image->GetHorizontalResolution();
resVer = image->GetVerticalResolution();

// Obtains real size
LengthImage = image->GetHeight();
WidthImage = image->GetWidth();

// Correction
LengthImage = (int)(96.0 / resVer * LengthImage);
WidthImage = (int)(96.0 / resHor * WidthImage);

Now, images are drawed correctly.

CBasicNet
April 22nd, 2008, 06:37 AM
Are you sure it is always 96 dpi?