GDI + using DrawImage to draw a translucent mask of the source image

Is it possible to draw a transparent image mask (i.e. draw all visible pixels with a constant color) with Graphics::DrawImage? I'm not looking to manually scan the image by pixels and create a separate image of the mask, I wonder if it is possible to draw it directly from the original image.

I suggest that this should be done with some manipulation with ImageAttributes, if possible at all.

The color of the mask is arbitrary and must be accurate, and this will be a plus if there can be a threshold transparency value.

+3
source share
2

- - RGB, - . - - + , , -. , , - 8- , :

g.DrawImage(&picture, r.left, r.top, r.Width(), r.Height()); // base image      

if ( AlphaBuf != NULL ) // do we have and alpha mask?
{
Gdiplus::Bitmap mask(Width, Height, Width(), PixelFormat8bppIndexed, AlphaBuf);
picture.GetPalette( palette, picture.GetPaletteSize() );
    // invert - only shows the transparent  
palette->Entries[0] = DLIMAKEARGB(255, 0, 0, 200); // 0 = fully transparent
palette->Entries[255] = DLIMAKEARGB(0, 0, 0, 0); // 255 = fully opaque 

mask.SetPalette(palette);
g.DrawImage(&mask, r.left, r.top, r.Width(), r.Height()); // draw the mask 
}

- , , - .

palette->Entries[1] = DLIMAKEARGB(254, 0, 0, 200);
palette->Entries[2] = DLIMAKEARGB(253, 0, 0, 200);
etc..

, (, , : -p)

+1

, , -, ?

, :

imageAttributes.SetColorMatrix( new ColorMatrix( new float[][] {
    new float[] {0, 0, 0, 0, 0},
    new float[] {0, 0, 0, 0, 0},
    new float[] {0, 0, 0, 0, 0},
    new float[] {0, 0, 0, 1, 0},
    new float[] {r, g, b, 0, 1}} ) );

r, g, b 0 1, :

float r = DesiredColor.R / 255f;
float g = DesiredColor.G / 255f;
float B = DesiredColor.B / 255f;

, " , ", ... , , , ?

0

Source: https://habr.com/ru/post/1719033/


All Articles