本文整理匯總了Java中javax.media.jai.JAI類的典型用法代碼示例。如果您正苦於以下問題:Java JAI類的具體用法?Java JAI怎麽用?Java JAI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JAI類屬於javax.media.jai包,在下文中一共展示了JAI類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: grayToGray256
import javax.media.jai.JAI; //導入依賴的package包/類
private static PlanarImage grayToGray256 (PlanarImage image)
{
System.out.println("Converting gray image to gray-256 ...");
ColorSpace colorSpace = ColorSpace.getInstance(java.awt.color.ColorSpace.CS_GRAY);
// int[] bits = new int[]{8};
// int opaque = Transparency.OPAQUE;
// int dataType = DataBuffer.TYPE_BYTE;
// ColorModel colorModel = new ComponentColorModel
// (colorSpace, bits, false, false, opaque, dataType);
return JAI.create("colorConvert", image, colorSpace, null);
}
示例2: writeRaster
import javax.media.jai.JAI; //導入依賴的package包/類
public void writeRaster(String file){
if(file == null) return;
// Encode data into buffered image
int width = getCols();
int height = getRows();
float[] data_ = new float[width * height];
for(int i = 0; i < data_.length; i++){
data_[i] = data[i / width][i % width];
}
// Using greyscale to store floating point values.
// Currently JAI doesn't support writing double precision (64-bit) samples to tiffs
// so we have to settle for standard 32-bit floating point values, which is crap
// ... so watch this space!
ImageTypeSpecifier spec = ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[]{0}, DataBuffer.TYPE_FLOAT, false, false);
BufferedImage img = spec.createBufferedImage(width, height);
img.getRaster().setPixels(0, 0, width, height, data_);
// Use JAI to write tiff file
JAI.create("filestore", img, file, "TIFF", null);
}
示例3: loadJAI
import javax.media.jai.JAI; //導入依賴的package包/類
/**
* Try to load an image, using JAI.
* This seems limited to a single image, thus no id parameter is to be
* provided.
*
* @param imgFile the input file
* @return a map of one image, or null if failed to load
*/
public static SortedMap<Integer, BufferedImage> loadJAI (File imgFile)
{
BufferedImage image = JAI.create("fileload", imgFile.getPath()).getAsBufferedImage();
try {
if ((image.getWidth() > 0) && (image.getHeight() > 0)) {
SortedMap<Integer, BufferedImage> images = new TreeMap<Integer, BufferedImage>();
images.put(1, image);
return images;
}
} catch (Exception ex) {
logger.debug(ex.getMessage());
}
return null;
}
示例4: getJaiLoader
import javax.media.jai.JAI; //導入依賴的package包/類
/**
* Try to use JAI.
*
* @param imgPath the provided input file
* @return proper (JAI) loader or null if failed
*/
private static Loader getJaiLoader (Path imgPath)
{
logger.debug("getJaiLoader {}", imgPath);
try {
BufferedImage image = JAI.create("fileload", imgPath.toString()).getAsBufferedImage();
if ((image != null) && (image.getWidth() > 0) && (image.getHeight() > 0)) {
return new JaiLoader(image);
}
logger.debug("No image read by JAI for {}", imgPath);
} catch (Exception ex) {
logger.warn("JAI failed opening {}, {} ", imgPath, ex.toString(), ex);
}
return null;
}
示例5: graphicFillLineString
import javax.media.jai.JAI; //導入依賴的package包/類
private static void graphicFillLineString(final LineSymbolizer symbolizer, final Shape shape, final Image image, final float size, final double opacity) {
Double width = new Double(Math.max(1, shape.getBounds2D().getWidth()));
Double height = new Double(Math.max(1, shape.getBounds2D().getHeight()));
Double shapeHeight = new Double(size);
double factor = shapeHeight.doubleValue() / image.getHeight(null);
Double shapeWidth = new Double(image.getWidth(null) * factor);
AffineTransform transform = AffineTransform.getTranslateInstance(shape.getBounds2D().getMinX(), shape.getBounds2D().getMinY());
Image scaledImage = image.getScaledInstance(shapeWidth.intValue(), shapeHeight.intValue(), Image.SCALE_FAST);
BufferedImage buff = new BufferedImage(shapeWidth.intValue(), shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
buff.getGraphics().drawImage(scaledImage, 0, 0, null);
ParameterBlock p = new ParameterBlock();
p.addSource(buff);
p.add(width.intValue());
p.add(height.intValue());
RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
BufferedImage bufferedImage = im.getAsBufferedImage();
glDrawImage(bufferedImage, transform, null);
bufferedImage.flush();
im.dispose();
scaledImage.flush();
buff.flush();
}
示例6: drawGraphicFillPolygon
import javax.media.jai.JAI; //導入依賴的package包/類
private static void drawGraphicFillPolygon(Image image, float size, Graphics2D graphics, double opacity, double widthSymbol, double heightSymbol, double offsetYSymbol, double offsetXSymbol) {
Double shapeHeight = new Double(size);
double factor = shapeHeight / image.getHeight(null);
Double shapeWidth = new Double(Math.max(image.getWidth(null) * factor, 1));
AffineTransform transform = AffineTransform.getTranslateInstance(offsetXSymbol, offsetYSymbol);
Image scaledImage = image.getScaledInstance(shapeWidth.intValue(), shapeHeight.intValue(), Image.SCALE_FAST);
BufferedImage buff = new BufferedImage(shapeWidth.intValue(), shapeHeight.intValue(), BufferedImage.TYPE_INT_ARGB);
buff.getGraphics().drawImage(scaledImage, 0, 0, null);
ParameterBlock p = new ParameterBlock();
p.addSource(buff);
p.add((int) widthSymbol);
p.add((int) heightSymbol);
RenderedOp im = JAI.create("pattern", p);//$NON-NLS-1$
BufferedImage bufferedImage = im.getAsBufferedImage();
graphics.drawImage(bufferedImage, transform, null);
bufferedImage.flush();
im.dispose();
scaledImage.flush();
buff.flush();
}
示例7: computeEdgeDensityClutter
import javax.media.jai.JAI; //導入依賴的package包/類
private double computeEdgeDensityClutter(PlanarImage image) {
// first compute the RenderedOp that computes both vertical and
// horizontal
// edge detection
KernelJAI sobelVertKernel = KernelJAI.GRADIENT_MASK_SOBEL_VERTICAL;
KernelJAI sobelHorizKernel = KernelJAI.GRADIENT_MASK_SOBEL_HORIZONTAL;
ParameterBlock pb = new ParameterBlock();
pb.addSource(image);
pb.add(sobelHorizKernel);
pb.add(sobelVertKernel);
RenderedOp renderedOp = JAI.create("gradientmagnitude", pb);
BufferedImage edgeImage = renderedOp.getAsBufferedImage();
// then compute a density value, i.e. the mean
int edgeTotal = 0;
for (int i = 0; i < edgeImage.getWidth(); i++)
for (int j = 0; j < edgeImage.getHeight(); j++)
edgeTotal += Math.abs(edgeImage.getRGB(i, j));
return Math.abs(edgeTotal / (edgeImage.getWidth() * edgeImage.getHeight()));
}
示例8: addBorder
import javax.media.jai.JAI; //導入依賴的package包/類
/**
* add a border to image
* @param thickness
* @param color
* @param borderType
*/
public void addBorder(int thickness, Color color, int borderType) throws ExpressionException{
double colorArray[] = {color.getRed(), color.getGreen(), color.getBlue()};
BorderExtender borderExtender = new BorderExtenderConstant(colorArray);
ParameterBlock params = new ParameterBlock();
params.addSource(image());
params.add(thickness);
params.add(thickness);
params.add(thickness);
params.add(thickness);
if(BORDER_TYPE_CONSTANT==borderType) params.add(borderExtender);
else params.add(BorderExtender.createInstance(borderType));
//else if(BORDER_TYPE_WRAP==borderType)params.add(BorderExtender.createInstance(BorderExtender.BORDER_REFLECT));
image((JAI.create("border", params)).getAsBufferedImage());
}
示例9: translate
import javax.media.jai.JAI; //導入依賴的package包/類
public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException {
RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION,interpolation);
if(interpolation!=RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) {
hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1)));
}
ParameterBlock pb = new ParameterBlock();
pb.addSource(image());
BufferedImage img = JAI.create("translate", pb).getAsBufferedImage();
Graphics2D graphics = img.createGraphics();
graphics.clearRect(0, 0, img.getWidth(), img.getHeight());
AffineTransform at = new AffineTransform();
at.setToIdentity();
graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans);
graphics.dispose();
image(img);
}
示例10: _rotate
import javax.media.jai.JAI; //導入依賴的package包/類
public void _rotate(float x, float y, float angle, String interpolation) throws ExpressionException {
float radiansAngle = (float)Math.toRadians(angle);
// rotation center
float centerX = (float)getWidth() / 2;
float centerY = (float)getHeight() / 2;
ParameterBlock pb = new ParameterBlock();
pb.addSource(image());
pb.add(centerX);
pb.add(centerY);
pb.add(radiansAngle);
pb.add(new javax.media.jai.InterpolationBicubic(10));
// create a new, rotated image
image(JAI.create("rotate", pb).getAsBufferedImage());
}
示例11: crop
import javax.media.jai.JAI; //導入依賴的package包/類
public void crop(float x, float y, float width, float height) throws ExpressionException {
ParameterBlock params = new ParameterBlock();
params.addSource(image());
params.add(x);
params.add(y);
float w = getWidth();
float h = getHeight();
if (w < x + width) params.add(w - x);
else params.add(width);
if (h < y + height) params.add(h - y);
else params.add(height);
image(JAI.create("crop", params).getAsBufferedImage());
}
示例12: readRaster
import javax.media.jai.JAI; //導入依賴的package包/類
public void readRaster(String file){
if(file == null || !new File(file).exists()){
// For recreating RevenueGrid
loaded = false;
//System.out.println("MatrixData.readRaster: not loaded " + id + ", " + file );
return;
}
loaded = true;
// Use JAI to read tiff file format
RenderedImage img = (RenderedImage)JAI.create("fileload", file);
// Extract data from image
int width = img.getWidth();
int height = img.getHeight();
float[] data_ = new float[width * height];
data_ = img.getData().getPixels(0, 0, width, height, data_);
data = new float[height][width];
for(int i = 0; i < data_.length; i++){
data[i / width][i % width] = data_[i];
}
// System.out.println(Utils.arrayString(data));
}
示例13: blur
import javax.media.jai.JAI; //導入依賴的package包/類
public void blur(int blurFactor) throws ExpressionException{
ParameterBlock params = new ParameterBlock();
params.addSource(image());
params.add(blurFactor);
RenderingHints hint= new RenderingHints(JAI.KEY_BORDER_EXTENDER,BorderExtender.createInstance(1));
image(JAI.create("boxfilter", params, hint).getAsBufferedImage());
}
示例14: createTargetProduct
import javax.media.jai.JAI; //導入依賴的package包/類
private void createTargetProduct() {
int sceneWidth = this.sourceProduct.getSceneRasterWidth();
int sceneHeight = this.sourceProduct.getSceneRasterHeight();
Dimension tileSize = JAI.getDefaultTileSize();
this.targetProduct = new Product(this.sourceProduct.getName() + "_grm", this.sourceProduct.getProductType(), sceneWidth, sceneHeight);
this.targetProduct.setPreferredTileSize(tileSize);
this.targetProduct.setSceneGeoCoding(this.sourceProduct.getSceneGeoCoding());
Band targetBand = new Band("band_1", ProductData.TYPE_INT32, sceneWidth, sceneHeight);
this.targetProduct.addBand(targetBand);
}
示例15: buildSourceProduct
import javax.media.jai.JAI; //導入依賴的package包/類
private static Product buildSourceProduct() {
int sceneRasterWidth = 20;
int sceneRasterHeight = 30;
Product product = new Product("tempProduct", "Test", sceneRasterWidth, sceneRasterHeight);
product.setPreferredTileSize(JAI.getDefaultTileSize());
Band band = product.addBand("band_1", ProductData.TYPE_INT16);
ProductData data = band.createCompatibleRasterData();
int index = 0;
for (int y=0; y<sceneRasterHeight;y++) {
for (int x=0; x<sceneRasterWidth;x++) {
int value = 50;
if ((x > 0 && x < sceneRasterWidth-1) && (y > 0 && y < sceneRasterHeight-1 && y % 5 == 0)) {
value = 150;
}
data.setElemIntAt(index++, value);
}
}
band.setData(data);
return product;
}