Java填充图像 [英] Java padding image

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

问题描述

我正在创建一个在线图像编辑工具,正在寻找参考,我如何添加右侧带有空白的图像.例如,参见此图像

I am working on creating an online image editing tool.Looking for some refernce how can I add an image with white space on right side.For example see this image

推荐答案

大概是要从现有图像创建新图像,而新图像的左右两侧都有空白?

Presumably, you want to create a new image from an existing image, where the new image has white space on the left and right?

假设未填充的图像是BufferedImage,称为图像".假设每边要使用的空白量为"w".您想要做的是创建一个比原始对象宽的新BufferedImage,然后将整个对象涂成白色,最后在其上方绘制较小的图像:

Suppose the unpadded image was a BufferedImage and is called 'image'. Suppose the amount of whitespace you want on each side is 'w'. What you want to do is create a new BufferedImage wider than the original, then paint the entire thing white, and finally draw the smaller image on top of it:

BufferedImage newImage = new BufferedImage(image.getWidth() + 2 * w, image.getHeight(), image.getType());

Graphics g = newImage.getGraphics();

g.setColor(Color.white);
g.fillRect(0, 0, image.getWidth() + 2 * w, image.getHeight());
g.drawImage(image, w, 0, null);
g.dispose();

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

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