CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2008
    Posts
    3

    How to create a pattern plus color brush using GDI Plus brush object

    I have some bitmaps in my resource and i am using those bitmaps to create a pattern for my GDI + brush, i can create the brush using

    HBITMAP bitmap = gPatternCache[(*q-11)].hBitmap; // gPatternCache --> array of pattern bitmaps handles...
    Bitmap *pattern = new Bitmap(bitmap,NULL);
    Brush *br = new TextureBrush(pattern);

    but in addition to that i also want to change the color of that brush, this color selection is done by end user. (i can create a brush of any color using SolidBrush br(obColor); but i cant create it with the patterns )
    Gdiplus::Color obColor(255,0,0);

    What i want is i want a pattern brush with any RGB color. Is there any way to do that??? please suggest some solution....

    My Entire code is as follows :

    HBITMAP bitmap = gPatternCache[(*q-11)].hBitmap;
    Bitmap *pattern = new Bitmap(bitmap,NULL);
    Brush *br = new TextureBrush(pattern);

    Graphics graphics(GetGlobalDC());
    GraphicsPath polyPath;
    polyPath.StartFigure();
    polyPath.AddArc(rect, stAngle, sweepAngle); // rect, stAngle & sweepAngle --> has some values....
    polyPath.CloseFigure();
    graphics.SetSmoothingMode(SmoothingModeHighQuality);
    //SolidBrush br(obColor);
    graphics.FillPath(br, &polyPath);

    Thanks in advance...

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to create a pattern plus color brush using GDI Plus brush object

    I think you're going to have to use different bitmap patterns where the bitmap colors are what you want. I don't think you can override the bitmap's color when using it as a pattern brush.

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Quote Originally Posted by hoxsiew View Post
    I don't think you can override the bitmap's color when using it as a pattern brush.
    You can override every pixel in that bitmap after it is loaded and before it is used to create patterned brush.
    In good old GDI (without +), the patterned brushes were monochrome, so you could control its color with text and background colors.
    Now with GDI+ you can use color bitmaps as a pattern, so the questions to OP are: what color is your pattern and how do you want to change it?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Feb 2008
    Posts
    3

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Quote Originally Posted by VladimirF View Post
    You can override every pixel in that bitmap after it is loaded and before it is used to create patterned brush.
    In good old GDI (without +), the patterned brushes were monochrome, so you could control its color with text and background colors.
    Now with GDI+ you can use color bitmaps as a pattern, so the questions to OP are: what color is your pattern and how do you want to change it?
    I have one dialogue box from which user can change the pattern and color of the object(object can be a rectangle or circle or anything)

    P.S --> I cant use the standard patterns of MFC, i have created some bitmaps in resource with some designs and i want to use that bitmap as a brush pattern.
    So if user selects pattern 1 and color as a red then that particular object should be filled with pattern 1 in red color.

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Quote Originally Posted by maheshmahindrakar View Post
    P.S --> I cant use the standard patterns of MFC, i have created some bitmaps in resource with some designs and i want to use that bitmap as a brush pattern.
    So if user selects pattern 1 and color as a red then that particular object should be filled with pattern 1 in red color.
    Once again: is your pattern colored? Using one solid color?
    I already suggested two ways:
    1. Use GDI with monochrome pattern and change text/background color.
    2. Run through each pixel of your pattern and modify its color.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    Feb 2008
    Posts
    3

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Ya this could work but i don't know how to change the color of bitmap pixel by pixel, if you have any example code or link then that will be very helpful.
    Thanks

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Your easiest solution might* be to just use a <24 bpp bitmap and manipulate the palette. Just change this line:

    Code:
    Bitmap *pattern = new Bitmap(bitmap,NULL);
    and use a palette appropriate for your color(s) instead of NULL.

    I say "might" because I'm not all that familiar with GDI+.

  8. #8
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to create a pattern plus color brush using GDI Plus brush object

    Quote Originally Posted by maheshmahindrakar View Post
    ... if you have any example code or link then that will be very helpful.
    MSDN has plenty.
    Here is one.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured