如何创建带有半透明色块的透明 gif/png 图像?
我想使用java以编程方式创建gif/png图像文件。该 gif/png 图像应该是透明的,并且指定矩形大小和指定位置的特定颜色块应该是半透明的。我有图像的高度和宽度(以像素为单位)。我还有放置矩形彩色半透明补丁的 x,y 坐标,并且还有该彩色半透明补丁的高度和宽度。
是否可以在 Java 中以编程方式创建具有上述规范的 gif/png 图像? 如何创建这样的 gif/png 图像?
由于我不知道java中的图像处理,请指导我的朋友来完成这个任务。
I want to create gif/png image file using java programatically. This gif/png image should be transparent and a certain patch of color of specified rectangular size and at specified location should be translucent. I have height and width of the image in pixels. I also have x,y coordinate placing that rectangular colored translucent patch and also have the height and width of that colored translucent patch.
Is it possible to create a gif/png image with above specification programatically in Java?
How to create such gif/png image?
As I don't know image processing in java please guide me friends to achieve this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个带有 Alpha 通道的 BufferedImage。获取图像的
Graphics
对象。给它画上你喜欢的任何东西。使用ImageIO
将其保存为 PNG。有关文档,请参阅每个类的 JavaDocs。对于教程,我推荐 Java 教程的 2D 图形 Trail。
至于演示。代码,我太忙了,无法浏览我的“一次性”代码来获取创建具有部分透明度的 PNG 的示例。特别是如果我发布它,您可能会抱怨部分透明的部分是圆形而不是正方形。
为什么不根据我已经提供的线索尽力而为,如果您遇到困难,请发布 sscce 您尽最大努力在帖子中编辑您的问题?
Create a
BufferedImage
with an alpha channel. Get theGraphics
object of the image. Paint to it whatever you like. Save it as a PNG usingImageIO
.For documentation, see the JavaDocs for each of those classes. For a tutorial, I recommend the 2D Graphics Trail of the Java Tutorial.
As for demo. code, I am too busy to go trawling through my 'throwaway' codes for an example of creating a PNG with partial transparency. Especially since if I posted it, you'd probably complain that the partially transparent part is a circle rather than a square.
Why not give it your best shot based on the leads I've already provided, and if you get stuck, post an sscce of your best effort to the thread as an edit to your question?