Bitmap image scaling and Printer resolution

Discussion in 'C++' started by jalpa11@hotmail.com, Jan 2, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. mlimber Guest

    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-lite/how-to-post.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
     
    mlimber, Jan 2, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    1,009
    Andrew FPGA
    Sep 26, 2005
  2. Bastard

    Printer resolution (again?)

    Bastard, Nov 21, 2003, in forum: Java
    Replies:
    0
    Views:
    520
    Bastard
    Nov 21, 2003
  3. Gandalf

    Masked bitmap from bitmap

    Gandalf, Jan 29, 2004, in forum: Python
    Replies:
    0
    Views:
    617
    Gandalf
    Jan 29, 2004
  4. Yann KERNIN

    Printing bitmap on HP Printer

    Yann KERNIN, Oct 25, 2006, in forum: C Programming
    Replies:
    3
    Views:
    355
    Keith Thompson
    Oct 25, 2006
  5. xqggz
    Replies:
    1
    Views:
    456
    Victor Bazarov
    Jun 19, 2007
Loading...

Share This Page