CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    May 2011
    Posts
    18

    [RESOLVED] Color Matrix and Transparency in Images

    Ok. I'm creating a "Custom" Panel to serve in displaying images. The purpose of this is to allow the developer to add a "BackImage" and a "Front Image" and then allow them to tweak the Transparency for both the Front Image, Back Image and then the combined images overall.

    The way I've got the code set up is to Buffer the BackImage, Buffer the Front Images....Draw both of those images to a single buffer and then draw that "combined" buffer to the control.

    Generally, this works just fine. However I'm running into something that I cannot figure out. At design-time, i have properties on my control that can adjust the transparency.... These work just fine. However, at run-time the opacity doesn't really work quite right.

    If the "overall" opactiy and "back image" opacity are at 100%, then the front image Opacity works just fine. I can adjust my sliders and it renders as i would have expected. However, if I start tweaking the other sliders for the BackImage and Overall Image, the opacity never changes for those. If i start out at say 10% for all images that no matter if i move the sliders up or down, my images slowly become opaque. And only will the Front image opacity render properly when all other image Alpha levels be at 100%. Very Strange.

    Also, if I don't have any back image specified, the front image doesn't change its opacity...

    This all did work when i rendered directly to the screen without using a texture brush and buffer. However, when implementing those features to reduce flicker, that is when I started noticing this odd behavior.

    I've attached my control and also the implementation of my test harness for review..

    I suspect it has to do with the Color Matrix for the individual images....BUT, it works in design time when i set each property in the property grid.. Just not at design time when i adjust my sliders..

    Here is how i set my ColorMatrix for each image buffer that gets created...


    private ImageAttributes GenerateImageAttributes(int opacity)
    {
    float[][] ptsArray ={
    new float[] {1, 0, 0, 0, 0},
    new float[] {0, 1, 0, 0, 0},
    new float[] {0, 0, 1, 0, 0},
    new float[] {0, 0, 0, (float)((float)opacity/100), 0},
    new float[] {0, 0, 0, 0, 1}};

    ColorMatrix clrMatrix = new ColorMatrix(ptsArray);


    ImageAttributes imgAttributes = new ImageAttributes();
    imgAttributes.SetColorMatrix(clrMatrix,ColorMatrixFlag.Default, ColorAdjustType.Bitmap);



    return imgAttributes;

    }
    Attached Files Attached Files

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