简体   繁体   English

用Java处理Alpha混合

[英]Processing alpha blending in Java

I'm working on processing and I'd like to recreate on low level code the function blend lightest. 我正在处理,我想在低级代码上重新创建功能最轻的混合。

I saw in documentation that C = max(A * factor, B) 我在文档中看到C = max(A * factor, B)

  • C is the returned color C是返回的颜色
  • A is the source A是来源
  • B is the image to mix with B是要混合的图像

I've seen on web that the factor specified is based on the alpha component of the source pixel, which is represented by the first 8 bits ( from the left ) of the 32-bit integer representing the pixel color. 我在网上看到,指定的系数基于源像素的alpha分量,该分量由代表像素颜色的32位整数的前8位(从左开始)表示。 These leftmost bits are also referred to as the highest bits. 这些最左边的位也称为最高位。

Source: this book , page 464 资料来源: 这本书 ,第464页

What should i think of it? 我应该怎么看?

This is my code of that part: 这是我那部分的代码:

for (int y = 0; y < capWidth * capHeight; y++) {
    int factor = (pixels[y] >> 24) & 0xFF;
    pixels[y] = max(pixels[y] * factor, previousFrame.pixels[y]);      
} 

That doesn't work, any help? 那行不通,有帮助吗?

  1. this won't work because the factor in your original formula is a floating-point number between 0 and 1, and the factor in your code is an integer from 0 to 255. 这将不起作用,因为原始公式中的factor是0到1之间的浮点数,而代码中的factor是0到255之间的整数。
  2. this isn't a formula for blending, not really. 这不是混合的公式,不是真的。 For blending you have to add the colors, not take the maximum 对于混合,您必须添加颜色,而不是最大

For each color: C = A(a/255) + B(1-(a/255)), where: 对于每种颜色:C = A(a / 255)+ B(1-(a / 255)),其中:

A is the foreground value, A是前景值,

B is the background value, B是背景值,

C is the resultant value, and C是结果值,并且

a is the alpha component. a是alpha分量。

This is per the alpha blending wiki page: http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending 这是根据Alpha混合Wiki页面进行的: http : //en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending

http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/index.html

I got it in here, the SVG processing javadoc for blending Lighten ! 我在这里得到了,SVG处理javadoc来混合Lighten! Well ! 好 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM