CSS 如何在png图像中找到像素的alpha通道透明度值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2131949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find the alpha channel transparency value of a pixel in a png image?
提问by Allen Bargi
I have an image that has alpha channel transparency.
我有一个具有 alpha 通道透明度的图像。
I want to recreate the same background color with RGBA values in CSS but I can not find the real color of the background pixels and their alpha channel value. if I use any sort of color picker it will give me the absolute value of the pixel color which is relevant to its background color.
我想在 CSS 中使用 RGBA 值重新创建相同的背景颜色,但我找不到背景像素的真实颜色及其 alpha 通道值。如果我使用任何类型的颜色选择器,它将为我提供与其背景颜色相关的像素颜色的绝对值。
Do you know any trick to find out the real alpha channel value of a pixel?
您知道找出像素的真实 Alpha 通道值的任何技巧吗?
回答by Roman Nurik
In Photoshop's Info panel, you can choose 'Opacity' as a readout mode, though it will show up as a percentage and not as a real alpha value.
在 Photoshop 的“信息”面板中,您可以选择“不透明度”作为读数模式,但它会显示为百分比而不是真正的 alpha 值。
To enable it, simply open the Infowindow, choose Panel Optionsand then set the Second Color Readoutmode to Opacity.
要启用它,只需打开信息窗口,选择面板选项,然后将第二颜色读数模式设置为不透明度。
回答by jomo
Using Gimp, you can usethe Color picker.
使用 Gimp,您可以使用颜色选择器。
Press shiftwhile clicking on a pixel.
(or tick Use info window
in the tool's options)
出版社shift同时在像素上点击。
(或Use info window
在工具选项中打勾)
Once you click on a pixel, the Color Picker Information window
will pop up, showing you details including the alpha level:
单击像素后,Color Picker Information window
将弹出,显示包括 alpha 级别在内的详细信息:
回答by Daniel Johansson
I found out a way to get the exactalpha value in Photoshop. The other solutions only get the closest integer percentage to the actual alpha.
我找到了一种在 Photoshop 中获得精确alpha 值的方法。其他解决方案只能获得与实际 alpha 最接近的整数百分比。
- Create a black background layer (#000000).
- Duplicate the layer whose alpha you need, because we need to edit it. (Or if you need the composite alpha of several layers, duplicate them and merge them)
- Hide the original layer, so that only the black background and the new duplicate is visible.
- Click the new layer and then click "Lock transparent pixels" (The little checkerboard icon above the layers)
- Fill the layer (Shift+Backspace) with White color.
- 创建一个黑色背景层(#000000)。
- 复制您需要其 alpha 的图层,因为我们需要对其进行编辑。(或者,如果您需要多个图层的合成 alpha,请复制它们并合并它们)
- 隐藏原始图层,以便只有黑色背景和新副本可见。
- 单击新图层,然后单击“锁定透明像素”(图层上方的小棋盘图标)
- 用白色填充图层(Shift+Backspace)。
Now you have a picture containing the alpha values of the original image, in greyscale. Just use the Color Picker to select any pixel in the image, and get the exact alpha value (for example #7f7f7f means an alpha of 0x7f, or 127).
现在您有一张包含原始图像的灰度值的图片。只需使用拾色器选择图像中的任何像素,并获得准确的 alpha 值(例如 #7f7f7f 表示 alpha 为 0x7f 或 127)。
回答by David Schaal
use the PS info panel and set second color readout mode to opacity. turn off the visibility of all layers except the layer of the object you are analyzing (background should be transparent checkerboard) -info now gives original rgb value and correct opacity that can be converted into rgba.
使用 PS 信息面板并将第二个颜色读出模式设置为不透明度。关闭除您正在分析的对象图层之外的所有图层的可见性(背景应该是透明棋盘格)-info 现在提供原始 rgb 值和正确的不透明度,可以转换为 rgba。
回答by matpol
use the absolute colour and adjust the transparency in photoshop until it looks right and then use that percentage as your value.
使用绝对颜色并在 Photoshop 中调整透明度,直到看起来正确,然后使用该百分比作为您的值。