如何鼠标下模糊的图像 [英] How to blur an image under the mouse
本文介绍了如何鼠标下模糊的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用Java开发的,并已生成的图像。当鼠标经过生成的图像,我需要的图像时使用模糊或像素化的过滤器。
我应该用什么样的方法来做到这一点?
解决方案
公共无效测试(INT X,int y)对{//此处x和y被抛出的mouseDragged参数( )函数
blur1 = displayImage; // blur1是可变的图像blur2 =新的BufferedImage(blur1.getWidth(本),blur1 // blur2是BufferedImage的变量
.getHeight(本),BufferedImage.TYPE_INT_RGB);
TST = blur2.createGraphics(); // TST是的Graphics2D变量
tst.drawImage(blur1,0,0,这一点);
blur3 =新的BufferedImage(blur1.getWidth(本),blur1 // blur3是BufferedImage的变量
.getHeight(本),BufferedImage.TYPE_INT_RGB);
浮点数据[] = {0.0625f,0.125f,0.0625f,0.125f,0.25f,0.125f,
0.0625f,0.125f,0.0625f};
内核内核=新的内核(3,3,数据);
卷积的ConvolveOp =新的ConvolveOp(内核,ConvolveOp.EDGE_NO_OP,
空值);
blur2 = OSC.getSubimage(X,Y,20,20); // 20是在像素的大小,其中施加的影响
blur3 = OSC.getSubimage(X,Y,20,20);
convolve.filter(blur2,blur3);
图形OSG = OSC.getGraphics();
osg.setColor(填充颜色);
osg.drawImage(blur3,X,Y,NULL);
osg.dispose();
重绘();
}
I am working in java, and have an image being generated. When the mouse passes over the generated image, I need the image to use a blur or pixelation filter.
What methods should I use to accomplish this?
解决方案
public void test(int x, int y){ // Here x and y are the parameter thrown by mouseDragged() function
blur1 = displayImage; // blur1 is Image variable
blur2 = new BufferedImage(blur1.getWidth(this), blur1 //blur2 is BufferedImage Variable
.getHeight(this), BufferedImage.TYPE_INT_RGB);
tst = blur2.createGraphics(); // tst is Graphics2D variable
tst.drawImage(blur1, 0, 0, this);
blur3 = new BufferedImage(blur1.getWidth(this), blur1 //blur3 is BufferedImage Variable
.getHeight(this), BufferedImage.TYPE_INT_RGB);
float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f,
0.0625f, 0.125f, 0.0625f };
Kernel kernel = new Kernel(3, 3, data);
ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
null);
blur2 = OSC.getSubimage(x, y, 20, 20); // 20 is the size in pixels where the effect is applied
blur3 = OSC.getSubimage(x, y, 20, 20);
convolve.filter(blur2, blur3);
Graphics osg = OSC.getGraphics();
osg.setColor(fillColor);
osg.drawImage(blur3,x,y,null);
osg.dispose();
repaint();
}
这篇关于如何鼠标下模糊的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文