通过从255中减去每个现有值,为每个像素生成互补色值. [英] generating the complementary colour values for each pixel by subtracting each existing value from 255.
本文介绍了通过从255中减去每个现有值,为每个像素生成互补色值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将此代码与跟踪栏一起使用,以便用户可以看到在滚动跟踪栏时逐步发生的效果.
I would like to use this code with a track bar so that the user can see the effects take place step by step as the track bar is scrolled.
Public Function translate(ByVal img As Image, ByVal red As Single, _
ByVal green As Single, ByVal blue As Single, _
Optional ByVal alpha As Single = 0) As Boolean
Dim sr, sg, sb, sa As Single
'' noramlize the color components to 1
sr = red / 255
sg = green / 255
sb = blue / 255
sa = alpha / 255
'' create the color matrix
dim New ColorMatrix(New Single()() _
{New Single() {1, 0, 0, 0, 0}, _
New Single() {0, 1, 0, 0, 0}, _
New Single() {0, 0, 1, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {sr, sg, sb, sa, 1}})
'' apply the matrix to the image
Return draw_adjusted_image(img, cm)
End Function
Private Function draw_adjusted_image(ByVal img As Image, _
ByVal cm As ColorMatrix) As Boolean
Try
Dim bmp As New Bitmap(img) '' create a copy of the source image
Dim imgattr As New ImageAttributes()
Dim rc As New Rectangle(0, 0, img.Width, img.Height)
Dim g As Graphics = Graphics.FromImage(img)
'' associate the ColorMatrix object with an ImageAttributes object
imgattr.SetColorMatrix(cm)
'' draw the copy of the source image back over the original image,
''applying the ColorMatrix
g.DrawImage(bmp, rc, 0, 0, img.Width, img.Height, _
GraphicsUnit.Pixel, imgattr)
g.Dispose()
Return True
Catch
Return False
End Try
End Function
我试图对其进行编辑,以使其适合我的系统,但未得到任何结果.
如果该过程连续两次应用,则原始图像应重新出现.
I have tried to edit it so that it fits into my system but am not getting any results.
If the process is applied twice in succession then the original image should reappear.
May I get assistance please?
推荐答案
请阅读以下有关CP的提示: ^ ].
希望有帮助!
Please read this tip on CP: Image (colour) manipulation with ColorMatrix[^].
Hope that helps!
这篇关于通过从255中减去每个现有值,为每个像素生成互补色值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文