| |

VerySource

 Forgot password?
 Register
Search
View: 678|Reply: 4

Why does this code display the bitmap in memory only in 2 colors?

[Copy link]

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-6 16:30:01
| Show all posts |Read mode
Why does this code display the bitmap in memory only in 2 colors?
 void StrectBMP (char * fileSrc, HDC ClientDc, double proportion)
{
BITMAP srcInfo;
HBITMAP HBmpSource = (HBITMAP) LoadImage (0, fileSrc, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
      
    HDC hsrc = CreateCompatibleDC (NULL);
HGDIOBJ hold = SelectObject (hsrc, HBmpSource);
GetObject (HBmpSource, sizeof (BITMAP), (LPVOID)&srcInfo);

HDC hDest = CreateCompatibleDC (NULL);
int mode = SetStretchBltMode (hDest, COLORONCOLOR);
// SelectStockObject (hDest, BLACK_BRUSH);
HBITMAP hmemBmp = CreateCompatibleBitmap (hDest, srcInfo.bmWidth,
                            srcInfo.bmHeight);
  HGDIOBJ holdsrc = SelectObject (hDest, hmemBmp);

BOOL b = StretchBlt (hDest, 0,0, srcInfo.bmWidth, srcInfo.bmHeight, hsrc, 0,0,
           srcInfo.bmWidth, srcInfo.bmHeight, SRCCOPY);

    b = BitBlt (ClientDc, 0,0, srcInfo.bmWidth, srcInfo.bmHeight, hDest, 0,0, SRCCOPY);
}
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-27 06:45:01
| Show all posts
ClientDc = GetDC (hWnd); // Window display area HDC
fileSrc is the bitmap file path.
Great help from everyone.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-27 12:15:02
| Show all posts
Change to
HBITMAP hmemBmp = CreateCompatibleBitmap (ClientDC, srcInfo.bmWidth,
                            srcInfo.bmHeight);
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-3-28 13:45:01
| Show all posts
Thank youfeng214. When my purpose is to reduce the bitmap in memory first and then get the bitmap data, BitBlt just wants to see the actual effect of memory mapping. I wonder if it can be implemented based on the above code?
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-3 17:00:01
| Show all posts
The problem has been resolved. Thank you all.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list