java代码去除水印 java去除图片背景

Aspose.Words for Java应用之一,word转png怎么去掉水印对于文档处理控件Aspose.wordsjava代码去除水?。木哂写硇缘墓δ苁窃诿挥邪沧癕icrosoft Word的情况下,也能实现生成、打印、渲染、邮件合并,文档格式转换等功能 。今天在使用Aspose.Words过程中 , 意外的发现这款文档处理软件的另外一个功能,它可以将图像转换为PDF文件,接下来就为大家分享一下实现这一功能的具体代码
如有疑问追问,如满意记得采纳,
如果有其他问题也可点java代码去除水印我名字向我求助
答题不易,
如果没有回答完全,请您谅解,
请采纳最快回答的正确答案?。⌒恍唬?
如何用java去除图片水?。?/h2>//运行以下程序即可
public class ImageInit {
BufferedImage image;
private int iw, ih;
private int[] pixels;
public ImageInit(BufferedImage image) {
this.image = image;
iw = image.getWidth();
ih = image.getHeight();
pixels = new int[iw * ih];
}
public BufferedImage changeGrey() {
PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih,
pixels, 0, iw);
try {
pg.grabPixels();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 设定二值化java代码去除水印的域值java代码去除水?。?默认值为100
int grey = 100;
// 对图像进行二值化处理java代码去除水印 , Alpha值保持不变
ColorModel cm = ColorModel.getRGBdefault();
for (int i = 0; iiw * ih; i++) {
int red, green, blue;
int alpha = cm.getAlpha(pixels[i]);
if (cm.getRed(pixels[i])grey) {
red = 255;
} else {
red = 0;
}
if (cm.getGreen(pixels[i])grey) {
green = 255;
} else {
green = 0;
}
if (cm.getBlue(pixels[i])grey) {
blue = 255;
} else {
blue = 0;
}
pixels[i] = alpha24 | red16 | green8 | blue; // 通过移位重新构成某一点像素的RGB值
}
// 将数组中的象素产生一个图像
Image tempImg = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(iw, ih, pixels, 0, iw));
image = new BufferedImage(tempImg.getWidth(null),
tempImg.getHeight(null), BufferedImage.TYPE_INT_BGR);
image.createGraphics().drawImage(tempImg, 0, 0, null);
return image;
}
public BufferedImage getMedian() {
PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih,
pixels, 0, iw);
try {
pg.grabPixels();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 对图像进行中值滤波,Alpha值保持不变
ColorModel cm = ColorModel.getRGBdefault();
for (int i = 1; iih - 1; i++) {
for (int j = 1; jiw - 1; j++) {
int red, green, blue;
int alpha = cm.getAlpha(pixels[i * iw + j]);
// int red2 = cm.getRed(pixels[(i - 1) * iw + j]);
int red4 = cm.getRed(pixels[i * iw + j - 1]);
int red5 = cm.getRed(pixels[i * iw + j]);
int red6 = cm.getRed(pixels[i * iw + j + 1]);
// int red8 = cm.getRed(pixels[(i + 1) * iw + j]);
// 水平方向进行中值滤波
if (red4 = red5) {
if (red5 = red6) {
red = red5;
} else {
if (red4 = red6) {
red = red6;
} else {
red = red4;
}
}
} else {
if (red4red6) {
red = red4;
} else {
if (red5red6) {
red = red6;
} else {
red = red5;
}
}
}
int green4 = cm.getGreen(pixels[i * iw + j - 1]);
int green5 = cm.getGreen(pixels[i * iw + j]);
int green6 = cm.getGreen(pixels[i * iw + j + 1]);
【java代码去除水印 java去除图片背景】// 水平方向进行中值滤波
if (green4 = green5) {
if (green5 = green6) {

推荐阅读