Solved

bitmap manipulation

Posted on 1998-11-18
4
228 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
Comment Utility
Edited text of question
0
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
Comment Utility
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
Comment Utility
Adjusted points to 200
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
10x :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now