Draw a transparent rectangle
-
Hi all, At runtime how to draw a transparent rectangle on the bitmap, which is loaded from the file using memory DC. thanks in advance
-
Hi all, At runtime how to draw a transparent rectangle on the bitmap, which is loaded from the file using memory DC. thanks in advance
-
Hi all, At runtime how to draw a transparent rectangle on the bitmap, which is loaded from the file using memory DC. thanks in advance
-
Hi all, At runtime how to draw a transparent rectangle on the bitmap, which is loaded from the file using memory DC. thanks in advance
See
Graphics::DrawRectangle
on the MSDN. -
what is the problem u r facing right now? if u r problem is that u r rectangle drawn with Rectangle()masks u r bmp then draw 4 lines simple.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
i'm having a CBitmap object, which will contain 2546x3288 size image,loading from bmp file.i need to draw a rectangle on that image witout lossing of background image...
void SFormViewer::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CWnd::OnPaint() for painting messages if(flag_iInitPaint) { CRect rClient; GetClientRect(&rClient); CPen m_Pen; m_Pen.CreatePen(PS_SOLID,2,RGB(250,0,0)); CDC m_memDC; m_memDC.CreateCompatibleDC(&dc); m_memDC.SelectObject(&m_FormImage); m_memDC.SelectObject(&m_Pen); m_memDC.SetBkMode(TRANSPARENT); r_SelectedRect.SetRect(m_iShownImgTopX + p_iTopLeft.x, m_iShownImgTopY + p_iTopLeft.y, m_iShownImgTopX + p_iBottomRight.x, m_iShownImgTopY + p_iBottomRight.y); if(flag_Scroll == 0) { m_memDC.Rectangle(r_SelectedRect); } dc.BitBlt(0,0,rClient.Width(),rClient.Height(),&m_memDC,m_iShownImgTopX,m_iShownImgTopY,SRCCOPY); } }
-
i'm having a CBitmap object, which will contain 2546x3288 size image,loading from bmp file.i need to draw a rectangle on that image witout lossing of background image...
void SFormViewer::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CWnd::OnPaint() for painting messages if(flag_iInitPaint) { CRect rClient; GetClientRect(&rClient); CPen m_Pen; m_Pen.CreatePen(PS_SOLID,2,RGB(250,0,0)); CDC m_memDC; m_memDC.CreateCompatibleDC(&dc); m_memDC.SelectObject(&m_FormImage); m_memDC.SelectObject(&m_Pen); m_memDC.SetBkMode(TRANSPARENT); r_SelectedRect.SetRect(m_iShownImgTopX + p_iTopLeft.x, m_iShownImgTopY + p_iTopLeft.y, m_iShownImgTopX + p_iBottomRight.x, m_iShownImgTopY + p_iBottomRight.y); if(flag_Scroll == 0) { m_memDC.Rectangle(r_SelectedRect); } dc.BitBlt(0,0,rClient.Width(),rClient.Height(),&m_memDC,m_iShownImgTopX,m_iShownImgTopY,SRCCOPY); } }
surezu wrote:
r_SelectedRect.SetRect(m_iShownImgTopX + p_iTopLeft.x, m_iShownImgTopY + p_iTopLeft.y, m_iShownImgTopX + p_iBottomRight.x, m_iShownImgTopY + p_iBottomRight.y); if(flag_Scroll == 0) { m_memDC.Rectangle(r_SelectedRect); }
what i suggest is, instead of using memDC.rectangle, use like this. say if you want to draw rectangle from (x1,y1) to (x2,y2) moveto(x1,y1); lineto(x2,y1); moveto(x2,y1); lineto(x2,y2); moveto(x2,y2); lineto(x1,y2); try to guess the next part of the code.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
surezu wrote:
r_SelectedRect.SetRect(m_iShownImgTopX + p_iTopLeft.x, m_iShownImgTopY + p_iTopLeft.y, m_iShownImgTopX + p_iBottomRight.x, m_iShownImgTopY + p_iBottomRight.y); if(flag_Scroll == 0) { m_memDC.Rectangle(r_SelectedRect); }
what i suggest is, instead of using memDC.rectangle, use like this. say if you want to draw rectangle from (x1,y1) to (x2,y2) moveto(x1,y1); lineto(x2,y1); moveto(x2,y1); lineto(x2,y2); moveto(x2,y2); lineto(x1,y2); try to guess the next part of the code.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
chandu004 wrote:
what i suggest is, instead of using memDC.rectangle,
Why is 8 lines of code better than 1? Inquiring minds want to know... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
surezu wrote:
draw a transparent rectangle
Here try the following code: void DrawTransparentRectangle( CDC& dc, Rect rc) { // the next line draws a transparent rectangle // there now can you see it? // i'm sure it is there, look again }
Ha! I can see right through your reply :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
i'm having a CBitmap object, which will contain 2546x3288 size image,loading from bmp file.i need to draw a rectangle on that image witout lossing of background image...
void SFormViewer::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here // Do not call CWnd::OnPaint() for painting messages if(flag_iInitPaint) { CRect rClient; GetClientRect(&rClient); CPen m_Pen; m_Pen.CreatePen(PS_SOLID,2,RGB(250,0,0)); CDC m_memDC; m_memDC.CreateCompatibleDC(&dc); m_memDC.SelectObject(&m_FormImage); m_memDC.SelectObject(&m_Pen); m_memDC.SetBkMode(TRANSPARENT); r_SelectedRect.SetRect(m_iShownImgTopX + p_iTopLeft.x, m_iShownImgTopY + p_iTopLeft.y, m_iShownImgTopX + p_iBottomRight.x, m_iShownImgTopY + p_iBottomRight.y); if(flag_Scroll == 0) { m_memDC.Rectangle(r_SelectedRect); } dc.BitBlt(0,0,rClient.Width(),rClient.Height(),&m_memDC,m_iShownImgTopX,m_iShownImgTopY,SRCCOPY); } }
Rectangle draws a rectangle filled with the current selected brush. Try selecting a null/hollow brush into the memDC instead of setting the background mode to transparent CBrush HollowBrush; HollowBrush.CreateStockObject(HOLLOW_BRUSH); CBrush *pOldBrush = m_memDC.SelectObject(&HollowBrush); ... <draw your rectangle> ... m_memDC.SelectObject(pOldBrush); It's also a good idea to get into the habit of saving objects previously selected into DCs so you can select them back in when you're done with the DC. This will prevent resource leak problems. Also....what happens if the bitmap isn't compatible with the memDC?? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: