Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split bitmap in Visual C++

Status
Not open for further replies.

adamsmith774

Programmer
Nov 27, 2003
4
GB
I'm pretty new to programming so its probably something simple.... when I put bitmaps into my project a veiw them in the resource editor they're fine, but in the program they're split down the middle with the left side displayed on the right.

Here's some of the code... the beginpaint and endpaint are in another section:

C hMemDC = CreateCompatibleDC(hDC);

// Select the bitmap into the device context

HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_hBitmap);

// Draw the bitmap to the destination device context

if (bTrans)
TransparentBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0,
GetWidth(), GetHeight(), crTransColor);

else BitBlt (hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY)


GetWidth and Getheight get the width and heights of the bitmaps.

bTrans is a boolean saying whether or not i'm using transparency.
 
try inverting the source rectanges width...

BitBlt (hDC, x, y, GetWidth(), GetHeight(), hMemDC, (-1 * GetWidth()), GetHeight(), SRCCOPY)

i notice also that with your BitBlt statement, you arent setting the source coordinates, but in the TransparentBlt call you are.

Which one is messing up in your code, or is it both of them?

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
I inverted it but it didnt make much difference...except only the transparent things were showing.


The picture isn't inverted like a mirror image. I think it starts drawing the picture in the middle-top of the rectangle and scans across to the right.... so it's missing half of the pixels from the top line.

For example, if it was drawing a face, the ears would be in the middle and the nose would be cut in half and displayed on the left and right edges of the rectangle. And there'd be a vertical black line down the centre.

Is there an anti-surrealist library I should be using?
 
BitBlt normally works ok, are you sure that your bitmap is a standard image?

try creating a bitmap in MS paint and see if it loads ok, save it with the most default options

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
I was using MS paint. Is there somewhere where I should be telling it which part of the rectangle to start blitting in?
 
Try this code, ive just written and tested it now with a 24bit bitmap i created in MS paint:


BITMAP bm;
HBITMAP hTest = NULL;
hTest = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_TEST));
HDC hdcMem = CreateCompatibleDC(hDC);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hTest);
GetObject(hTest, sizeof(bm), &bm);
BitBlt(hDC, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);



Try pasting that code into your project and see if it works ok.

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
No luck... it just did the same thing. Thanks very much though. Any chance I can blame it on the computer?? I'm using XP, VC++6.0, and I only have 32MB ram.

I've read that there are a few problems with the image editor in VC++... is it anything to do with that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top