本文整理汇总了Java中java.awt.image.ConvolveOp类的典型用法代码示例。如果您正苦于以下问题:Java ConvolveOp类的具体用法?Java ConvolveOp怎么用?Java ConvolveOp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConvolveOp类属于java.awt.image包,在下文中一共展示了ConvolveOp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HeapView
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public HeapView() {
// Configure structures needed for rendering drop shadow.
int kw = KERNEL_SIZE, kh = KERNEL_SIZE;
float blurFactor = BLUR_FACTOR;
float[] kernelData = new float[kw * kh];
for (int i = 0; i < kernelData.length; i++) {
kernelData[i] = blurFactor;
}
blur = new ConvolveOp(new Kernel(kw, kh, kernelData));
format = new MessageFormat("{0,choice,0#{0,number,0.0}|999<{0,number,0}}/{1,choice,0#{1,number,0.0}|999<{1,number,0}}MB");
heapSizeText = "";
// Enable mouse events. This is the equivalent to adding a mouse
// listener.
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
setToolTipText(NbBundle.getMessage(GarbageCollectAction.class, "CTL_GC"));
updateUI();
}
示例2: apply
import java.awt.image.ConvolveOp; //导入依赖的package包/类
@Override
public final BufferedImage apply(BufferedImage img) {
float[][] matrix = getMatrix();
float[] data = getKernelData(matrix);
if(normalize)
normalize(data);
scale(data);
if(isZero(data))
return new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
Kernel k = new Kernel(matrix[0].length, matrix.length, data);
ConvolveOp op = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, null);
BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
img2.getGraphics().drawImage(img, 0, 0, null);
return op.filter(img2, null);
}
示例3: enableConvolveOp
import java.awt.image.ConvolveOp; //导入依赖的package包/类
private static void enableConvolveOp(RenderQueue rq,
SurfaceData srcData,
ConvolveOp cop)
{
// assert rq.lock.isHeldByCurrentThread();
boolean edgeZero =
cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
Kernel kernel = cop.getKernel();
int kernelWidth = kernel.getWidth();
int kernelHeight = kernel.getHeight();
int kernelSize = kernelWidth * kernelHeight;
int sizeofFloat = 4;
int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);
RenderBuffer buf = rq.getBuffer();
rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
buf.putInt(ENABLE_CONVOLVE_OP);
buf.putLong(srcData.getNativeOps());
buf.putInt(edgeZero ? 1 : 0);
buf.putInt(kernelWidth);
buf.putInt(kernelHeight);
buf.put(kernel.getKernelData(null));
}
示例4: blur
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public static BufferedImage blur(BufferedImage src) {
BufferedImage bufferedImage = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
int s1 = 7;
int s2 = 7;
float level = .1f / 9f;
float[] filter = new float[s1 * s2];
for (int i = 0; i < s1 * s2; i++) {
filter[i] = level;
}
Kernel kernel = new Kernel(s1, s2, filter);
BufferedImageOp op = new ConvolveOp(kernel);
bufferedImage = op.filter(src, null);
return bufferedImage;
}
示例5: crashTest
import java.awt.image.ConvolveOp; //导入依赖的package包/类
private static void crashTest() {
Raster src = createSrcRaster();
WritableRaster dst = createDstRaster();
ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP);
try {
op.filter(src, dst);
} catch (ImagingOpException e) {
/*
* The test pair of source and destination rasters
* may cause failure of the medialib convolution routine,
* so this exception is expected.
*
* The JVM crash is the only manifestation of this
* test failure.
*/
}
System.out.println("Test PASSED.");
}
示例6: effect_blur
import java.awt.image.ConvolveOp; //导入依赖的package包/类
/**
* Blur the image
* @param amount
*/
public void effect_blur(int amount) { // TODO
int radius = amount;
int size = radius * 2 + 1;
float weight = 1.0f / (size * size);
float[] data = new float[size * size];
for (int i = 0; i < data.length; i++) {
data[i] = weight;
}
Kernel kernel = new Kernel(size, size, data);
ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
image = op.filter(image, null);
}
示例7: getBlurredImg
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public static Image getBlurredImg(BufferedImage img) {
final int kernel_size = 15;
float[] blurKernel = new float[kernel_size * kernel_size];
final float blurPeakHeight = 0.35f;
double[][] sigma = new double[2][2];
sigma[0] = new double[]{1.2, 0.0};
sigma[1] = new double[]{0.0, 1.2};
double mid = (kernel_size / 2.0);
float cent = (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{mid, mid});
for (int i = 0; i < blurKernel.length; i++) {
int x = i / kernel_size;
int y = i % kernel_size;
blurKernel[i] = blurPeakHeight * (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{x, y}) / cent;
}
ConvolveOp op = new ConvolveOp(new Kernel(kernel_size, kernel_size, blurKernel));
return op.filter(img, null);
}
示例8: toSVG
import java.awt.image.ConvolveOp; //导入依赖的package包/类
/**
* @param op BufferedImageOp to be converted to SVG
* @param filterRect Rectangle, in device space, that defines the area
* to which filtering applies. May be null, meaning that the
* area is undefined.
* @return an SVGFilterDescriptor representing the SVG filter
* equivalent of the input BufferedImageOp
*/
public SVGFilterDescriptor toSVG(BufferedImageOp op,
Rectangle filterRect){
SVGFilterDescriptor filterDesc =
svgCustomBufferedImageOp.toSVG(op, filterRect);
if(filterDesc == null){
if(op instanceof LookupOp)
filterDesc = svgLookupOp.toSVG(op, filterRect);
else if(op instanceof RescaleOp)
filterDesc = svgRescaleOp.toSVG(op, filterRect);
else if(op instanceof ConvolveOp)
filterDesc = svgConvolveOp.toSVG(op, filterRect);
}
return filterDesc;
}
示例9: main
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public static void main(final String[] _args) {
String fileName = _args.length == 1 ? _args[0] : "Leo720p.wmv";
float[] convMatrix3x3 = new float[] {
0f,
-10f,
0f,
-10f,
41f,
-10f,
0f,
-10f,
0f
};
new JJMPEGPlayer("lab_6.alternate", fileName, convMatrix3x3){
@Override protected void processFrame(Graphics2D _gc, float[] _convMatrix3x3, BufferedImage _in, BufferedImage _out) {
java.awt.image.Kernel conv = new java.awt.image.Kernel(3, 3, _convMatrix3x3);
ConvolveOp convOp = new ConvolveOp(conv, ConvolveOp.EDGE_NO_OP, null);
convOp.filter(_in, _out);
}
};
}
示例10: blurImage
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public static BufferedImage blurImage(BufferedImage image)
{
float ninth = 1.0f/9.0f;
float[] blurKernel = {
ninth, ninth, ninth,
ninth, ninth, ninth,
ninth, ninth, ninth
};
Map<RenderingHints.Key, Object> map = new HashMap<RenderingHints.Key, Object>();
map.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
map.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
map.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
RenderingHints hints = new RenderingHints(map);
BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints);
return op.filter(image, null);
}
示例11: lock
import java.awt.image.ConvolveOp; //导入依赖的package包/类
/**
* @param time
*/
public void lock(final int time) {
frame.getGlassPane().setVisible(false);
screen = createScreenShot();
frame.getGlassPane().setVisible(true);
if (screen != null) {
gray = ImageProvider.convertToGrayScale(screen);
final float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f };
final Kernel kernel = new Kernel(3, 3, data);
final ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
final BufferedImage dest = new BufferedImage(gray.getWidth(), gray.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
gray = convolve.filter(gray, dest);
frame.setGlassPane(this);
frame.getGlassPane().setVisible(true);
fadeIn(time);
}
}
示例12: getBlurFilter
import java.awt.image.ConvolveOp; //导入依赖的package包/类
public static ConvolveOp getBlurFilter(int radius) {
if (radius < 1) {
throw new IllegalArgumentException("Radius must be >= 1");
}
int size = radius * 2 + 1;
float weight = 1.0f / (size * size);
float[] data = new float[size * size];
for (int i = 0; i < data.length; i++) {
data[i] = weight;
}
Kernel kernel = new Kernel(size, size, data);
return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
}
示例13: processImage
import java.awt.image.ConvolveOp; //导入依赖的package包/类
/**
* Uses a blur filter on an image in an attempt to make it readable by the
* QRCodeReader.
*
* @param image
* the page in a BufferedImage object
* @return another BufferedImage object with the filters applied to it
*/
private BufferedImage processImage(BufferedImage image) {
// default: 3x3 filter for a 72 DPI image
double DEFAULT_SIZE = 9.0;
// calculate filtering matrix size based on the image resolution
int dimension = (int) Math.sqrt(DEFAULT_SIZE
/ (double) DEFAULT_RESOLUTION * RETAKE_RESOLUTION);
int size = dimension * dimension;
float[] matrix = new float[size];
for (int i = 0; i < size; i++)
matrix[i] = 1.0f / (float) size;
BufferedImageOp op = new ConvolveOp(new Kernel(dimension, dimension,
matrix), ConvolveOp.EDGE_NO_OP, null);
return op.filter(image, null);
}
示例14: getDropShadowImage
import java.awt.image.ConvolveOp; //导入依赖的package包/类
/**
* Returns a drop shadow for the given rectangle specified by the given width and height.
* @param gc the graphics configuration
* @param w the rectangle width
* @param h the rectangle height
* @param sw the
* @param color the shadow color
* @return BufferedImage
*/
public static final BufferedImage getDropShadowImage(GraphicsConfiguration gc, int w, int h, int sw, Color color) {
// create a new image of the right size
BufferedImage image = gc.createCompatibleImage(w + 2 * sw, h + 2 * sw, Transparency.TRANSLUCENT);
Graphics2D ig2d = image.createGraphics();
ig2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ig2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// render the shadow rectangle
ig2d.setColor(color);
ig2d.fillRect(sw, sw, w, h);
ig2d.dispose();
// perform the linear blur
ConvolveOp op = ImageUtilities.getLinearBlurOp(sw);
return op.filter(image, null);
}
示例15: getConvolveOp
import java.awt.image.ConvolveOp; //导入依赖的package包/类
private ConvolveOp getConvolveOp(int blurRadius, double dpiFactor) {
blurRadius = (int) (blurRadius * dpiFactor);
final int blurRadius2 = blurRadius * blurRadius;
final float blurRadius2F = blurRadius2;
// final float weight = (float) (1.0 / blurRadius2F / dpiFactor);
final float weight = (float) (1.0 / blurRadius2F);
final float[] elements = new float[blurRadius2];
for (int k = 0; k < blurRadius2; k++) {
elements[k] = weight;
}
final Kernel myKernel = new Kernel(blurRadius, blurRadius, elements);
// if EDGE_NO_OP is not selected, EDGE_ZERO_FILL is the default which
// creates a black border
return new ConvolveOp(myKernel, ConvolveOp.EDGE_NO_OP, null);
}