SetPixel(Color.black)与任何颜色的Set Pixel之间的差异

时间:2022-02-07 20:04:24

When you create a new Bitmap and use the SetPixel() function and set the parameter Black color the result is same as when you don't set any color for specified pixel and save the bitmap in Jpeg format. After i save my image and i read Jpeg image file later how should i know the pixel has real Black color or is not set?

当您创建新的位图并使用SetPixel()函数并设置参数黑色时,结果与您没有为指定像素设置任何颜色并以Jpeg格式保存位图时的结果相同。保存我的图像后,我读了Jpeg图像文件,我怎么知道像素有真正的黑色或未设置?

3 个解决方案

#1


1  

You should use PNG. It is compressed image format. Its main benefits over JPEG are that it's lossless and supports transparency. On simple images that only have a few colors, I have experienced even smaller image sizes using PNG.

你应该使用PNG。它是压缩图像格式。它与JPEG相比的主要优点是它无损并支持透明度。在只有少量颜色的简单图像上,我使用PNG体验了更小的图像尺寸。

If you for some reason just have to use JPEG, I would use some specific color to express "no pixel". If you want to use black (0, 0, 0) as this color key, you have to use different color for true black pixels. This could be for example be 0x000001 (0, 0, 1). Eyes are unable to different it from true black but a computer program can. So if there is 0x000000 (0, 0, 0) colored pixels in image just replace it with 0x000001 (0, 0, 1). Be careful though, JPEG's lossy compression can cause problems when using this technique. Using higher quality should solve this problem.

如果你出于某种原因只需要使用JPEG,我会使用一些特定的颜色来表达“无像素”。如果要使用黑色(0,0,0)作为此颜色键,则必须使用不同的颜色作为真正的黑色像素。例如,这可以是0x000001(0,0,1)。眼睛无法与真正的黑色区别开来,但计算机程序可以。因此,如果图像中有0x000000(0,0,0)个彩色像素,则将其替换为0x000001(0,0,1)。但是要小心,JPEG的有损压缩在使用这种技术时会引起问题。使用更高的质量应解决这个问题。

#2


1  

“Not set” and “black” are the same in a JPEG. By default, it’s black. In a format with transparency, like 32-bit PNG, is where you’re going to be able to tell the difference.

“未设置”和“黑色”在JPEG中是相同的。默认情况下,它是黑色的。在具有透明度的格式中,如32位PNG,您将能够区分它们。

#3


1  

JPEG files don't support transparency so every pixel has some color - whether you explicitly set it or not. That's why it doesn't matter that you didnt' set a certain pixel's color - when you save the bitmap as JPEG, all pixels will be saved with some color. The ones you didn't set will be saved with the default which is black.

JPEG文件不支持透明度,因此每个像素都有一些颜色 - 无论您是否明确设置它。这就是为什么你没有设置某个像素的颜色并不重要 - 当你将位图保存为JPEG时,所有像素都会以某种颜色保存。您未设置的那些将以默认值黑色保存。

When you use an image format, such as PNG, that supports transparency, there's another 'color' available (which is the default): the transparent color. This is the color that's used by default for pixels that are not explicitly set.

当您使用支持透明度的图像格式(如PNG)时,可以使用另一种“颜色”(默认值):透明色。这是默认情况下未明确设置的像素使用的颜色。

Note that the transparent color is not really a separate color: each pixel has a transparency byte (assuming the pixel format is ARGB) and by default the transparency byte is set to 255 (full transparency) for each pixel. So the transparency of each pixel can be controlled independently of others.

请注意,透明颜色实际上不是单独的颜色:每个像素都有一个透明度字节(假设像素格式为ARGB),默认情况下,每个像素的透明度字节设置为255(完全透明)。因此,每个像素的透明度可以独立于其他像素进行控制。

#1


1  

You should use PNG. It is compressed image format. Its main benefits over JPEG are that it's lossless and supports transparency. On simple images that only have a few colors, I have experienced even smaller image sizes using PNG.

你应该使用PNG。它是压缩图像格式。它与JPEG相比的主要优点是它无损并支持透明度。在只有少量颜色的简单图像上,我使用PNG体验了更小的图像尺寸。

If you for some reason just have to use JPEG, I would use some specific color to express "no pixel". If you want to use black (0, 0, 0) as this color key, you have to use different color for true black pixels. This could be for example be 0x000001 (0, 0, 1). Eyes are unable to different it from true black but a computer program can. So if there is 0x000000 (0, 0, 0) colored pixels in image just replace it with 0x000001 (0, 0, 1). Be careful though, JPEG's lossy compression can cause problems when using this technique. Using higher quality should solve this problem.

如果你出于某种原因只需要使用JPEG,我会使用一些特定的颜色来表达“无像素”。如果要使用黑色(0,0,0)作为此颜色键,则必须使用不同的颜色作为真正的黑色像素。例如,这可以是0x000001(0,0,1)。眼睛无法与真正的黑色区别开来,但计算机程序可以。因此,如果图像中有0x000000(0,0,0)个彩色像素,则将其替换为0x000001(0,0,1)。但是要小心,JPEG的有损压缩在使用这种技术时会引起问题。使用更高的质量应解决这个问题。

#2


1  

“Not set” and “black” are the same in a JPEG. By default, it’s black. In a format with transparency, like 32-bit PNG, is where you’re going to be able to tell the difference.

“未设置”和“黑色”在JPEG中是相同的。默认情况下,它是黑色的。在具有透明度的格式中,如32位PNG,您将能够区分它们。

#3


1  

JPEG files don't support transparency so every pixel has some color - whether you explicitly set it or not. That's why it doesn't matter that you didnt' set a certain pixel's color - when you save the bitmap as JPEG, all pixels will be saved with some color. The ones you didn't set will be saved with the default which is black.

JPEG文件不支持透明度,因此每个像素都有一些颜色 - 无论您是否明确设置它。这就是为什么你没有设置某个像素的颜色并不重要 - 当你将位图保存为JPEG时,所有像素都会以某种颜色保存。您未设置的那些将以默认值黑色保存。

When you use an image format, such as PNG, that supports transparency, there's another 'color' available (which is the default): the transparent color. This is the color that's used by default for pixels that are not explicitly set.

当您使用支持透明度的图像格式(如PNG)时,可以使用另一种“颜色”(默认值):透明色。这是默认情况下未明确设置的像素使用的颜色。

Note that the transparent color is not really a separate color: each pixel has a transparency byte (assuming the pixel format is ARGB) and by default the transparency byte is set to 255 (full transparency) for each pixel. So the transparency of each pixel can be controlled independently of others.

请注意,透明颜色实际上不是单独的颜色:每个像素都有一个透明度字节(假设像素格式为ARGB),默认情况下,每个像素的透明度字节设置为255(完全透明)。因此,每个像素的透明度可以独立于其他像素进行控制。