How to improve image quality when painting images with Gdiplus::TextureBrush

Chau Dang Ba 50 Reputation points
2025-03-03T08:06:39.73+00:00

I am currently having a problem with broken image drawing

when I use Gdiplus::TextureBrush.

I know that when drawing images with Graphics::DrawImage, the image still maintains the image quality.

But I need to draw images with Gdiplus::TextureBrush because it can be customized to draw images in more ways (eg: repeat images, rotate images, draw according to matrix....). But the problem here is that when drawing images with Gdiplus::TextureBrush, the image quality will be low. Can you help me improve the image quality when drawing with Gdiplus::TextureBrush? Thank you

Windows development | Windows API - Win32
{count} vote

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2025-03-12T07:50:35.88+00:00

    Hi @Chau Dang Ba ,

    I'm glad your problem has been resolved. Let me summarise the issue to help anyone experiencing the same problem.

    TextureBrush usually fill shapes with an image-based texture. If you want to fill a region with a repeating texture, TextureBrush is a good choice.

    DrawImage is used to render an image directly at a specific coordinate with optional scaling or transformations.

    Depending on your screenshot, DrawImage seems to be a better choice for EMF files. You can use GraphicsPath and Graphics::SetClip to set a fan shape on Graphics, the use DrawImage to draw the image on Graphics.

     // Define the fan shape
     GraphicsPath path = new GraphicsPath();
     path.AddLine(new Point(50, 50), new Point(150, 50));
     path.AddArc(new Rectangle(50, 50, 100, 100), 0, 90);
     path.AddLine(new Point(150, 150), new Point(50, 150));
     path.AddArc(new Rectangle(50, 50, 100, 100), 180, 90);
    
     graphics
    

    Thank you.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.