Skip to content

ScottPlot4 Heatmap: Add Opacity property#2484

Merged
swharden merged 8 commits intoScottPlot:mainfrom
bukkideme:main
Mar 18, 2023
Merged

ScottPlot4 Heatmap: Add Opacity property#2484
swharden merged 8 commits intoScottPlot:mainfrom
bukkideme:main

Conversation

@bukkideme
Copy link
Contributor

Following #2461. Please have a look, what do you think?
Thanks!

@swharden
Copy link
Member

Hi @bukkideme, thanks for opening this PR!

I spent way too much time looking into this topic 🤪 but I learned something System.Drawing can do that I didn't previously appreciate

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-use-a-color-matrix-to-set-alpha-values-in-images?view=netframeworkdesktop-4.8

ColorMatrix cm = new() { Matrix33 = (float)Opacity }; // define opacity using a matrix
ImageAttributes att = new();
attr.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

gfx.DrawImage( // draw the heatmap using the custom matrix
        image: BmpHeatmap,
        destRect: destRect,
        srcX: 0,
        srcY: 0,
        BmpHeatmap.Width,
        BmpHeatmap.Height,
        GraphicsUnit.Pixel,
        attr);

This is a shortcut that lets us control global opacity without actually calculating any Color values. By adding an Opacity property (not passing it into functions) we can keep the original API the same and also not add any logic to check whether multiple types of opacity settings are being used. I'll update this PR to use this simpler method and merge it in shortly 🚀

@swharden swharden changed the title Introducing single opacity value option for all heatmap cells via the… ScottPlot4 Heatmap: Add Opacity property Mar 18, 2023
@swharden swharden enabled auto-merge March 18, 2023 19:29
@swharden swharden linked an issue Mar 18, 2023 that may be closed by this pull request
@swharden swharden merged commit b4d3b8f into ScottPlot:main Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

single double opacity value optionally in Heatmap.Update() method?

3 participants