Gradient Texture with Transparency
-
Does anybody have an idea how to draw an image (like using
TextureBrush
) with gradient transparency (like usingLinearGradientBrush
)? The only examples I can find on drawing an image with transparency useColorMatrix
to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is aLinearGradientTextureBrush
, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions."Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown
-
Does anybody have an idea how to draw an image (like using
TextureBrush
) with gradient transparency (like usingLinearGradientBrush
)? The only examples I can find on drawing an image with transparency useColorMatrix
to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is aLinearGradientTextureBrush
, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions."Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown
In case anyone cares. Until I find a nicer cleaner way to accomplish this, I've decided to brute force it pixel by pixel. For my purposes, the image is meant to be a background image for a range between 0 and 255. This example does the gradient vertically. To do a different direction, I assume anybody who cares can work out the necessary changes. I'll settle for this only because my image will be very small, but I'd still like to find a more elegant solution.
private Image GradientTransparent(Image src) {
Rectangle bmpBox = new Rectangle(0, 0, src.Width, src.Height);
Bitmap bmp = new Bitmap(src);
Graphics g = Graphics.FromImage(bmp);
for (int y = 0; y < bmp.Height; y++) {
// image is meant to represent a range from 0 to 255
int alpha = (int)((float)y * 255f / (float)bmp.Height);
for (int x = 0; x < bmp.Width; x++) {
Color pixel = bmp.GetPixel(x, y);
pixel = Color.FromArgb(alpha, pixel);
bmp.SetPixel(x, y, pixel);
}
}
return bmp;
}"Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown
-
Does anybody have an idea how to draw an image (like using
TextureBrush
) with gradient transparency (like usingLinearGradientBrush
)? The only examples I can find on drawing an image with transparency useColorMatrix
to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is aLinearGradientTextureBrush
, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions."Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown
I found something called OpacityMasks here: http://msdn.microsoft.com/en-us/library/ms743320(v=vs.85).aspx#creatingopacitymasks[^], but it seems to be for WPF only so it might not be an option for you. Regards,
-
I found something called OpacityMasks here: http://msdn.microsoft.com/en-us/library/ms743320(v=vs.85).aspx#creatingopacitymasks[^], but it seems to be for WPF only so it might not be an option for you. Regards,
WPF is outside the scope of this project, but I appreciate the link. It does look interesting. :-D
"Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown