在Java中混合图像 [英] Blending images in java

查看:64
本文介绍了在Java中混合图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我的游戏引擎运行流畅,并且在所有机器上都运行完美!在继续向引擎添加功能之前,我想增强引擎的图形功能.我关注的是淡入淡出和融合图像.我将需要一些平滑的过渡,因此在不使用任何第三方库(例如OpenGL)的情况下,当绘制图形对象时,如何将不透明度应用于图像?

Well I've got my game engine running smoothly, and perfectly on all machines! Before I continue adding functionality to the engine, I want to enhance the engine's graphical capabilities. The one I'm focused on is fading and blending images. I'm going to need some smooth transitions, so without using any 3rd party libraries like OpenGL, how does one apply opacity to images when drawing to a graphics object?

感谢您的答复:D

推荐答案

也许使用

Perhaps using an AlphaComposite could be what you're looking for?

Image image = new Image(...);
float alpha = 0.5;
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
    g2d.setComposite(composite);
    g2d.drawImage(image, 0, 0, null);
}

您可以将Alpha设置为所需的任何透明度级别(介于0.0和1.0之间).在这种情况下,您可能希望使用 AlphaComposite.SRC_OVER ,以便您可以覆盖透明图像并在透明图像后方查看,除非您要进行其他操作(如果这样,则可以在提供的第一个链接上轻松查看所有可用的常量及其说明).

You would set your alpha to whatever transparency level you desire (between 0.0 and 1.0). In this case, you would probably want to be using AlphaComposite.SRC_OVER to be able to overlay your transparent image and see behind it, unless your going for something else (if so, you can easily see all available constants and their explanations on the first link provided).

这篇关于在Java中混合图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆