1
votes

I'm currently using 5MP Camera, so I convert BYTE* to GDI+ Bitmap object and uses Graphics object to draw on picture control (all GDI+ objects)

and I want to draw a string on it and when I do so, resolution (quality or whatsoever) gets strange. here're the images.

Original image (Captured)

this is the original image

Text on it

this is the image with the text on it

And here's my code. it uses MFC's WM_MOUSEMOVE. and when mouse pointer gets on CRect(dispRC[array]), it renders string "aa" on the Bitmap object.

and when I do so, quality of image gets lower or I don't exactly know it changes the IMAGE. (You might not notice because those are captured images, but latter image's quality gets lower.)

void CSmall_StudioDlg::OnMouseMove(UINT nFlags, CPoint point)
{
    CPoint insidePoint;
// MAXCAM is the number of bitmap objects.
    for (int i = 0; i < MAXCAM; i++)
    {
// m_pBitmap[MAXCAM] is array of Bitmap* which contains address of Gdiplus::Bitmap objects.
        if (m_pBitmap[i] != NULL)
        {
// m_rcDisp[MAXCAM] are CRect objects which has information of picture control.
// i.e. GetDlgItem(IDC_BIN_DISP)->GetWindowRect(m_rcDisp[BINARY_VID]);
            if (point.x > m_rcDisp[i].TopLeft().x && point.y > m_rcDisp[i].TopLeft().y)
            {
                if (point.x < m_rcDisp[i].BottomRight().x && point.y < m_rcDisp[i].BottomRight().y)
                {
                    StringFormat SF;

                    insidePoint.x = point.x - m_rcDisp[i].TopLeft().x;
                    insidePoint.y = point.y - m_rcDisp[i].TopLeft().y;

                    Graphics textG(m_pBitmap[i]);
                    textG.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel);
                    Gdiplus::Font F(L"Palatino Linotype Bold", 10, FontStyleBold, UnitPixel);
                    RectF R(insidePoint.x, insidePoint.y, 20, 100);

                    SF.SetAlignment(StringAlignmentCenter);
                    SF.SetLineAlignment(StringAlignmentCenter);

                    SolidBrush B(Color(0, 0, 0));

                    textG.DrawString(_T("aa"), -1, &F, R, &SF, &B);
// m_pGraphics[MAXCAM] is made like this
// i.e.
// static CClientDC roiDc(GetDlgItem(IDC_ROI_DISP));
// m_hDC[ROI_VID] = roiDc.GetSafeHdc();
// m_pGraphics[ROI_VID] = Graphics::FromHDC(m_hDC[ROI_VID]);
                    m_pGraphics[i]->DrawImage(m_pBitmap[i], 0, 0, m_vidwidth[i], m_vidheight[i]);
                }
            }
        }

        
    }

    CDialogEx::OnMouseMove(nFlags, point);
}

Hope I get a helpful answer.

Thanks!

1
General advice applies: Don't render except in response to a WM_PAINT message. The only thing to do in the WM_MOUSEMOVE handler is to record the required information and trigger a repaint, usually by calling InvalidateRect. This may or may not solve the issue you are ultimately trying to address. Whether it will cannot be deduced from the information provided. A minimal reproducible example is needed, though static CClientDC suits itself well to implement a resource leak.IInspectable
As @IInspectable said, I think is wrong place to put rendering code in OnMouseMove ... perhaps if you move all this code into OnPaint / OnDraw handler your issue will solve it.flaviu2
Thanks for @IInspectable and flaviu2's answer but sadly it wasn't the cause. (I've moved drawing part to onpaint..) the resolution / quality problem still occurs. all I did is rendering text on the img. All I'm wondering is, does drawing text on the Bitmap object through graphics memory DC affects on resolution or quality of the image??21stDivision
@IInspectable and on minimal reproducible example's issue, here's my project (github.com/Glt-Hub/small_studio) but I don't know whether you can run this because it requires a camera to run the project. and plus, comments are Korean :(21stDivision
The minimal reproducible example needs to be in the question itself. It needs to be minimal, too.IInspectable

1 Answers

1
votes

I had a similar problem and solved it by creating the GDI+ font from a Windows font like this:

Gdiplus::Font font(hDc, hFont);

where hDc is a DC handle and hFont is a font handle.

Can you try if this helps?