VB .NET picture GetPixel & SetPixel: Include alpha?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 09:26:59

问题


I am trying to use GetPixel and SetPixel to copy the contents of one picture to another (I know there are other methods to do so, but there are reasons I want to try this ;D)

Anyway, the pictures are .png images, so they include transparency settings.

But for some reason, it seems like when I use GetPixel & SetPixel to put one image over another, it seems the second image completely replaces the other one. I mean, it seems the transparency settings are not respected when I use GetPixel & SetPixel.

Both images have the same size. Both have transparent areas.


回答1:


Before calling SetPixel() you need to call MakeTransparnet(). Here's some code that copies the contents of the first pixel in an alpha-image onto another image and retain's the first image's alpha channel:

    Using img1 = New Bitmap("c:\Users\Owner\Desktop\1.png")
        PX = img1.GetPixel(0, 0)
    End Using

    Using img2 = New Bitmap("c:\Users\Owner\Desktop\2.png")
        img2.MakeTransparent() '//Sets the transparent value and converts the image to Format32bppArgb
        img2.SetPixel(0, 0, PX)
        img2.Save("c:\Users\Owner\Desktop\3.png")
    End Using


来源:https://stackoverflow.com/questions/4610970/vb-net-picture-getpixel-setpixel-include-alpha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!