Solved

bitmap manipulation

Posted on 1998-11-18
4
230 Views
Last Modified: 2010-04-01
i wanna know how can i map a grey level bitmap image from a size of nxm
(n and m are the width and height of the bitmap) to a size of NxM ( a different width and height) without any change in its resolution.

can anyone point me to the right source code ???
0
Comment
Question by:syepeng
  • 2
  • 2
4 Comments
 

Author Comment

by:syepeng
ID: 1178201
Edited text of question
0
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1178202
you can use the StrecthBlt() command..

Here is a snippet code...
===================
hdcScaled = CreateCompatibleDC(hdcScreen);  
 
    hbmScaled = CreateCompatibleBitmap(hdcScreen,
                    GetDeviceCaps(hdcScreen, HORZRES) * 2,
                    GetDeviceCaps(hdcScreen, VERTRES) * 2);
 
    if (hbmScaled == 0)
        errhandler("hbmScaled", hwnd);
 
    /* Select the bitmaps into the compatible DC. */
 
    if (!SelectObject(hdcScaled, hbmScaled))
        errhandler("Scaled Bitmap Selection", hwnd);
 
case WM_COMMAND:     /* message: command from application menu */

    switch(wParam) {
 
        case IDM_SCALEX1:
            if (fBlt){
                 fScaled = FALSE;
                 hdcWin = GetDC(hwnd);
                 BitBlt(hdcWin,
                    0,0,
                    bmp.bmWidth, bmp.bmHeight,
                    hdcCompatible,
                    0,0,
                    SRCCOPY);
                 ReleaseDC(hwnd, hdcWin);
            }
            break;
 
        case IDM_SCALEX2:
            if (fBlt){

                 fScaled = TRUE;
                 StretchBlt(hdcScaled,
                     0, 0,
                     bmp.bmWidth * 2, bmp.bmHeight * 2,
                     hdcCompatible,
                     0, 0,
                     bmp.bmWidth, bmp.bmHeight,
                     SRCCOPY);
 
                 hdcWin = GetDC(hwnd);
                 BitBlt(hdcWin,
                    0,0,
                    bmp.bmWidth, bmp.bmHeight,
                    hdcScaled,

                    0,0,
                    SRCCOPY);
                 ReleaseDC(hwnd, hdcWin);
            }
            break;
=============
some parameters stuff....
------------------------
The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. Windows stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.

BOOL StretchBlt(

    HDC hdcDest,      // handle of destination device context
    int nXOriginDest,      // x-coordinate of upper-left corner of dest. rect.
    int nYOriginDest,      // y-coordinate of upper-left corner of dest. rect.
    int nWidthDest,      // width of destination rectangle
    int nHeightDest,      // height of destination rectangle
    HDC hdcSrc,      // handle of source device context
    int nXOriginSrc,      // x-coordinate of upper-left corner of source rectangle
    int nYOriginSrc,      // y-coordinate of upper-left corner of source rectangle
    int nWidthSrc,      // width of source rectangle
    int nHeightSrc,      // height of source rectangle
    DWORD dwRop       // raster operation code
   );      
 

Parameters

hdcDest

Identifies the destination device context.

nXOriginDest

Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.

nYOriginDest

Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.

nWidthDest

Specifies the width, in logical units, of the destination rectangle.

nHeightDest

Specifies the height, in logical units, of the destination rectangle.

hdcSrc

Identifies the source device context.

nXOriginSrc

Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.

nYOriginSrc

Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.

nWidthSrc

Specifies the width, in logical units, of the source rectangle.

nHeightSrc

Specifies the height, in logical units, of the source rectangle.

dwRop

Specifies the raster operation to be performed. Raster operation codes define how Windows combines colors in output operations that involve a brush, a source bitmap, and a destination bitmap.
------------------------
Hope this helps you get your things done :)

Cheers,
Viktor
0
 

Author Comment

by:syepeng
ID: 1178203
Adjusted points to 200
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1178204
10x :)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question