问题描述
我正在尝试使用GetPixel和SetPixel将一张图片的内容复制到另一张图片(我知道还有其他方法可以这样做,但是出于某些原因,我想尝试一下; D)
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)
无论如何,这些图片是.png图像,因此它们包含透明度设置。
Anyway, the pictures are .png images, so they include transparency settings.
但是由于某种原因,似乎当我使用GetPixel时& SetPixel将一个图像放在另一个图像上,似乎第二个图像完全替代了另一个图像。我的意思是,当我使用GetPixel&时,似乎不尊重透明度设置。 Setpixel。
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.
推荐答案
在调用SetPixel()之前,您需要调用。以下是一些代码,可将Alpha图像中第一个像素的内容复制到另一个图像上,并保留第一个图像的Alpha通道:
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
这篇关于VB .NET图片GetPixel& SetPixel:包括Alpha吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!