473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Bitmap image scaling and Printer resolution

Hi all,

I have one EMF image which I want to convert to BMP. I want to scale
the BMP and want to display it in my viewport area. If scaled BMP
doesn't fit inside the viewport area then I want to change the scale
such that image can fit inside it.

If device is screen then my image gets scaled properly and fits inside
the viewport area. But if my device is printer then my image gets
scaled properly but it doesn't fit inside the viewport area. This is so
as printer has very high resolution and thus the number of pixels of
the scaled image are very high >1000 pixels.

I pass ViewportwidhtInMM, ViewportheightInMM, Scale,
DeviceHorzPixelsPerMM, DeviceVertPixelsPerMM to my function which
generates scaled BMP from EMF.
My code is as follow:
{
HENHMETAFILE hemf;
HBITMAP bitmap;
HDC memDC;
ENHMETAHEADER emh;

emf = ::GetEnhMetaFile(strFileName);

// Get the header from the enhanced metafile.
ZeroMemory( &emh, sizeof(ENHMETAHEADER) );
emh.nSize = sizeof(ENHMETAHEADER);
if( GetEnhMetaFileHeader( hemf, sizeof( ENHMETAHEADER ), &emh ) == 0 )
{
DeleteEnhMetaFile( hemf );
return FALSE;
}

RECT rect;
float fAspectRatio;

long lWidth,lHeight;
long xFrame, yFrame;

lWidth = ((long)((float)(emh.rclFrame.right - emh.rclFrame.left) /
(100.0f))) * Scale;
lHeight = ((long)((float)(emh.rclFrame.bottom - emh.rclFrame.top) /
(100.0f))) * Scale;

lWidth = lWidth * DeviceHorzPixelsPerMM;
lHeight = lHeight * DeviceVertPixelsPerMM;

ViewPortWidth = ViewPortWidth * DeviceHorzPixelsPerMM;
ViewPortHeight = ViewPortHeight * DeviceVertPixelsPerMM;

if((ViewPortWidth < lWidth) || (ViewPortHeight < lHeight))
{
if((lWidth/lHeight) == 1)
{
xFrame = min(ViewPortWidth, ViewPortHeight);
yFrame = min(ViewPortWidth, ViewPortHeight);
}
else
{
fAspectRatio = (float)lWidth/(float)lHeight;
if(fAspectRatio 1 ) //width is more than height
{
xFrame = ViewPortWidth;
yFrame = (long)((float)ViewPortHeight / fAspectRatio);
}
else //width is less than height(or equal to height)
{
yFrame = ViewPortHeight;
xFrame = (long)((float)ViewPortWidth * fAspectRatio);
}
}
}
else
{
xFrame = lWidth;
yFrame = lHeight;
}
lWidth = xFrame;
lHeight = yFrame;
- - - - -
}
Then I create BMP with lWidht X lHeight pixels which in case of printer
comes very high.

Thanks for any help.

Jan 2 '07 #1
1 4728

ja*****@hotmail.com wrote:
Hi all,

I have one EMF image which I want to convert to BMP. I want to scale
the BMP and want to display it in my viewport area. If scaled BMP
doesn't fit inside the viewport area then I want to change the scale
such that image can fit inside it.

If device is screen then my image gets scaled properly and fits inside
the viewport area. But if my device is printer then my image gets
scaled properly but it doesn't fit inside the viewport area. This is so
as printer has very high resolution and thus the number of pixels of
the scaled image are very high >1000 pixels.

I pass ViewportwidhtInMM, ViewportheightInMM, Scale,
DeviceHorzPixelsPerMM, DeviceVertPixelsPerMM to my function which
generates scaled BMP from EMF.
My code is as follow:
{
HENHMETAFILE hemf;
HBITMAP bitmap;
HDC memDC;
ENHMETAHEADER emh;

emf = ::GetEnhMetaFile(strFileName);

// Get the header from the enhanced metafile.
ZeroMemory( &emh, sizeof(ENHMETAHEADER) );
emh.nSize = sizeof(ENHMETAHEADER);
if( GetEnhMetaFileHeader( hemf, sizeof( ENHMETAHEADER ), &emh ) == 0 )
{
DeleteEnhMetaFile( hemf );
return FALSE;
}

RECT rect;
float fAspectRatio;

long lWidth,lHeight;
long xFrame, yFrame;

lWidth = ((long)((float)(emh.rclFrame.right - emh.rclFrame.left) /
(100.0f))) * Scale;
lHeight = ((long)((float)(emh.rclFrame.bottom - emh.rclFrame.top) /
(100.0f))) * Scale;

lWidth = lWidth * DeviceHorzPixelsPerMM;
lHeight = lHeight * DeviceVertPixelsPerMM;

ViewPortWidth = ViewPortWidth * DeviceHorzPixelsPerMM;
ViewPortHeight = ViewPortHeight * DeviceVertPixelsPerMM;

if((ViewPortWidth < lWidth) || (ViewPortHeight < lHeight))
{
if((lWidth/lHeight) == 1)
{
xFrame = min(ViewPortWidth, ViewPortHeight);
yFrame = min(ViewPortWidth, ViewPortHeight);
}
else
{
fAspectRatio = (float)lWidth/(float)lHeight;
if(fAspectRatio 1 ) //width is more than height
{
xFrame = ViewPortWidth;
yFrame = (long)((float)ViewPortHeight / fAspectRatio);
}
else //width is less than height(or equal to height)
{
yFrame = ViewPortHeight;
xFrame = (long)((float)ViewPortWidth * fAspectRatio);
}
}
}
else
{
xFrame = lWidth;
yFrame = lHeight;
}
lWidth = xFrame;
lHeight = yFrame;
- - - - -
}
Then I create BMP with lWidht X lHeight pixels which in case of printer
comes very high.
This group deals with the standard C++ *language*
(http://www.parashift.com/c++-faq-lit....html#faq-5.9),
whereas your question is platform-specific and ths off-topic. Please
try a group dedicated to your platform/development environment (see
that FAQ for a partial list).

Cheers! --M

Jan 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Stephane D'Alu | last post by:
Do you know if it is possible to have an image to be scalled to a maximum width/height, but with keeping its aspect ratio. The two ideas I had were: - <img src="toto.jpg" style="max-width:...
2
by: TCR | last post by:
Hi, I posted this earlier and got a suggestion that didn't pan out. I am trying to determine if there is a known bug related to the resolution value returned when opening a .jpg file by passing...
8
by: James Dean | last post by:
I have 1 bit per pixel information and i have the width and height of this data.Each bit corresponds to a 24 bit colour value. I want to convert this to 24bit per pixel bitmap. Do i need to...
2
by: Sharon | last post by:
I encountered a strange behavior when doing ‘new Bitmap’: The following code works fine and the given bitmap file is shown on the PictureBox (the m_DrawArea) in the correct bitmap sizes: ...
4
by: CG3000 | last post by:
I create a .PNG image ( in Macromedia Fireworks ) which has an gif in it in the top left corner and a lot of empty canvas space to the right. I use about 10 text boxes on a form to populate...
4
by: Andrew | last post by:
Hi, I'm trying to blit small bitmaps onto a larger bitmap, and I've got a few issues wrt positioning and output size. I think my problems are due to DPI differences... My small images are...
3
by: =?Utf-8?B?SlIx?= | last post by:
I would like to add text to an image. I have tried to use DrawString and it works on some images but on others it is very very small. I am pretty sure it has something to do with the size of the...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
7
by: RB0135 | last post by:
Hi All, I have some Windows BMP, 1BPP, monochrome files that I need to get the raw data from to load a graphics buffer on a Roll Printer (which I know can be done). Lets forget about the Roll...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.