You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That article helped me a lot to massively speed up an image invert and color change in powershell.
But what is the "W" in the color space here? I tried to find anything, but all search results link back to this article.
Thank you for your response in the 24th of December! I suspected too, but...
How or when is it applied? I changed the fifth value to 0, 0.5, 1, 1000, -1000 in each row. And the outcome is no different, pixel exact the same transformation as the rest of that colormatrix says.
Is it applied only when a specific colorspace is used? The source and destination picture it is applied to is: [System.Drawing.Imaging.PixelFormat]::Format24bppRgb. Or is there something else how this value is used?
The whole powershell code used is this, to invert a white background diagram into dark color scheme and then gamma up the lower values to be better visible as a non-intrusive regularly updated windows wallpaper. $bmp is the original to be transformed. (Code to update the currently shown wallpaper is left out)
# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.colormatrix
$ColorMatrix = [System.Drawing.Imaging.ColorMatrix]::new( [float[][]] @(
[float[]](-0.2, 0, 0, 0, 0), # Invert R
[float[]](0, -0.2, 0, 0, 0), # Invert G
[float[]](0, 0, -0.2, 0, 0), # Invert B
[float[]](0, 0, 0, 1, 0), # Alpha: Do nothing
[float[]](0.2, 0.2, 0.2, 0, 1) # Translate/Offset RGBA
)
)
# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.imageattributes
$ImageAttributes = [System.Drawing.Imaging.ImageAttributes]::new()
$ImageAttributes.SetColorMatrix($ColorMatrix)
# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.imageattributes.setgamma
$ImageAttributes.SetGamma(0.6)
$bmpinv = [System.Drawing.Bitmap]::new($bmp.Width,$bmp.Height,[System.Drawing.Imaging.PixelFormat]::Format24bppRgb)
$pictinv = [System.Drawing.Graphics]::FromImage($bmpinv)
$pictinv.DrawImage($bmp, # Source image
[System.Drawing.Rectangle]::new(0,0,$bmp.Width,$bmp.Height), # Destination rectangle, here same as source
0,0,$bmp.Width,$bmp.Height, # Source rectangle.
[System.Drawing.GraphicsUnit]::Pixel, # We want 1:1 not inch or whatever
$ImageAttributes # Finally the matrix
)
$bmpinv.Save("$DataBaseDir\today-inv.png",[System.Drawing.Imaging.ImageFormat]::Png)
$pictinv.Dispose()
$bmpinv.Dispose()
Type of issue
Missing information
Description
That article helped me a lot to massively speed up an image invert and color change in powershell.
But what is the "W" in the color space here? I tried to find anything, but all search results link back to this article.
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.colormatrix?view=windowsdesktop-9.0
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Drawing.Imaging/ColorMatrix.xml
Document Version Independent Id
965b4c7a-083d-b594-f75d-e4f63b71e2e0
Article author
@dotnet-bot
The text was updated successfully, but these errors were encountered: