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...
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.
Re: How to create a pattern plus color brush using GDI Plus brush object
Quote:
Originally Posted by
hoxsiew
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?
Re: How to create a pattern plus color brush using GDI Plus brush object
Quote:
Originally Posted by
VladimirF
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.
Re: How to create a pattern plus color brush using GDI Plus brush object
Quote:
Originally Posted by
maheshmahindrakar
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.
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
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+.
Re: How to create a pattern plus color brush using GDI Plus brush object
Quote:
Originally Posted by
maheshmahindrakar
... if you have any example code or link then that will be very helpful.
MSDN has plenty.
Here is one.