当前位置: 首页>>代码示例>>Java>>正文


Java RenderedImage类代码示例

本文整理汇总了Java中java.awt.image.RenderedImage的典型用法代码示例。如果您正苦于以下问题:Java RenderedImage类的具体用法?Java RenderedImage怎么用?Java RenderedImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RenderedImage类属于java.awt.image包,在下文中一共展示了RenderedImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import java.awt.image.RenderedImage; //导入依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
  RenderedImage img = image.getRenderedImage();
  if (stream == null) {
    throw new IOException("Set an output first!");
  }
  if (param == null) {
    param = getDefaultWriteParam();
  }
  Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
  if (param.getSourceRegion() != null) {
    sourceRegion = sourceRegion.intersection(param.getSourceRegion());
  }
  Raster raster = img.getData(sourceRegion);
  int quality = 85;
  if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
    quality = (int) (param.getCompressionQuality() * 100);
  }
  try {
    stream.write(lib.encode(raster, quality).array());
  } catch (TurboJpegException e) {
    throw new IOException(e);
  }
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:25,代码来源:TurboJpegImageWriter.java

示例2: prepareInsertEmpty

import java.awt.image.RenderedImage; //导入依赖的package包/类
public void prepareInsertEmpty(int imageIndex,
                               ImageTypeSpecifier imageType,
                               int width,
                               int height,
                               IIOMetadata imageMetadata,
                               List<? extends BufferedImage> thumbnails,
                               ImageWriteParam param) throws IOException {
    checkParamsEmpty(imageType, width, height, thumbnails);

    this.isInsertingEmpty = true;

    SampleModel emptySM = imageType.getSampleModel();
    RenderedImage emptyImage =
        new EmptyImage(0, 0, width, height,
                       0, 0, emptySM.getWidth(), emptySM.getHeight(),
                       emptySM, imageType.getColorModel());

    insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
           param, false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TIFFImageWriter.java

示例3: toGraphicFile

import java.awt.image.RenderedImage; //导入依赖的package包/类
public void toGraphicFile(File file) throws IOException {

        Image image = createImage(getWidth(), getHeight());
        paint(image.getGraphics());
        image = new ImageIcon(image).getImage();

        BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics g = bufferedImage.createGraphics();
        g.drawImage(image, 0, 0, Color.WHITE, null);
        g.dispose();

        try {
            ImageIO.write((RenderedImage) bufferedImage, "PNG", file);
        } catch (IllegalArgumentException ex) {
        }
    }
 
开发者ID:Cvarier,项目名称:2D-Elliptic-Mesh-Generator,代码行数:17,代码来源:PlotCanvas.java

示例4: toGraphicFile

import java.awt.image.RenderedImage; //导入依赖的package包/类
public void toGraphicFile(File file) throws IOException {
    // otherwise toolbar appears
    plotToolBar.setVisible(false);

    Image image = createImage(getWidth(), getHeight());
    paint(image.getGraphics());
    image = new ImageIcon(image).getImage();

    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.createGraphics();
    g.drawImage(image, 0, 0, Color.WHITE, null);
    g.dispose();

    // make it reappear
    plotToolBar.setVisible(true);

    try {
        ImageIO.write((RenderedImage) bufferedImage, "PNG", file);
    } catch (IllegalArgumentException ex) {
    }
}
 
开发者ID:Cvarier,项目名称:2D-Elliptic-Mesh-Generator,代码行数:22,代码来源:PlotPanel.java

示例5: getIndexedImage

import java.awt.image.RenderedImage; //导入依赖的package包/类
protected RenderedImage getIndexedImage() {
    IndexColorModel icm = getIndexColorModel();

    BufferedImage dst =
        new BufferedImage(src.getWidth(), src.getHeight(),
                          BufferedImage.TYPE_BYTE_INDEXED, icm);

    WritableRaster wr = dst.getRaster();
    for (int y =0; y < dst.getHeight(); y++) {
        for (int x = 0; x < dst.getWidth(); x++) {
            Color aColor = getSrcColor(x,y);
            wr.setSample(x, y, 0, findColorIndex(root, aColor));
        }
    }

    return dst;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:PaletteBuilder.java

示例6: write_IDAT

import java.awt.image.RenderedImage; //导入依赖的package包/类
private void write_IDAT(RenderedImage image) throws IOException {
    IDATOutputStream ios = new IDATOutputStream(stream, 32768);
    try {
        if (metadata.IHDR_interlaceMethod == 1) {
            for (int i = 0; i < 7; i++) {
                encodePass(ios, image,
                           PNGImageReader.adam7XOffset[i],
                           PNGImageReader.adam7YOffset[i],
                           PNGImageReader.adam7XSubsampling[i],
                           PNGImageReader.adam7YSubsampling[i]);
                if (abortRequested()) {
                    break;
                }
            }
        } else {
            encodePass(ios, image, 0, 0, 1, 1);
        }
    } finally {
        ios.finish();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:PNGImageWriter.java

示例7: createFromRenderedImage

import java.awt.image.RenderedImage; //导入依赖的package包/类
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes the
 * layout of a <code>RenderedImage</code> (which may be a
 * <code>BufferedImage</code>).
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if <code>image</code> is
 * <code>null</code>.
 */
public static
    ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }

    if (image instanceof BufferedImage) {
        int bufferedImageType = ((BufferedImage)image).getType();
        if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
            return getSpecifier(bufferedImageType);
        }
    }

    return new ImageTypeSpecifier(image);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ImageTypeSpecifier.java

示例8: write_IDAT

import java.awt.image.RenderedImage; //导入依赖的package包/类
private void write_IDAT(RenderedImage image, int deflaterLevel)
    throws IOException
{
    IDATOutputStream ios = new IDATOutputStream(stream, 32768,
                                                deflaterLevel);
    try {
        if (metadata.IHDR_interlaceMethod == 1) {
            for (int i = 0; i < 7; i++) {
                encodePass(ios, image,
                           PNGImageReader.adam7XOffset[i],
                           PNGImageReader.adam7YOffset[i],
                           PNGImageReader.adam7XSubsampling[i],
                           PNGImageReader.adam7YSubsampling[i]);
                if (abortRequested()) {
                    break;
                }
            }
        } else {
            encodePass(ios, image, 0, 0, 1, 1);
        }
    } finally {
        ios.finish();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PNGImageWriter.java

示例9: handleFileSaveAction

import java.awt.image.RenderedImage; //导入依赖的package包/类
@FXML
private void handleFileSaveAction(ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    File file = fileChooser.showSaveDialog(null);
    
    if (file != null) {
        try {
            WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight());
            drawingCanvas.snapshot(null, writableImage);
            RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);            
            ImageIO.write(renderedImage, "png", file);
        } catch (IOException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
开发者ID:kmhasan-class,项目名称:spring2017java,代码行数:17,代码来源:FXMLDocumentController.java

示例10: handleFileSaveAction

import java.awt.image.RenderedImage; //导入依赖的package包/类
@FXML
private void handleFileSaveAction(ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    File file = fileChooser.showSaveDialog(null);
    System.out.println("Saving #" + file + "#");
    if (file != null) {
        // Stole the following part from:
        // http://java-buddy.blogspot.com/2013/04/save-canvas-to-png-file.html
        try {
            WritableImage writableImage = new WritableImage((int) drawingCanvas.getWidth(), (int) drawingCanvas.getHeight());
            drawingCanvas.snapshot(null, writableImage);
            RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);
            // hometask: make sure you can save files in any format (not just png)
            // hints: find the extension of the file from the filename, then use substring
            ImageIO.write(renderedImage, "png", file);
        } catch (IOException ex) {
            System.err.println("Couldn't save the file!");
            // hometask: throw an alert dialog from here
        }
    }
}
 
开发者ID:kmhasan-class,项目名称:spring2017java,代码行数:22,代码来源:FXMLDocumentController.java

示例11: needToCreateIndex

import java.awt.image.RenderedImage; //导入依赖的package包/类
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:GIFImageWriter.java

示例12: resizeImage

import java.awt.image.RenderedImage; //导入依赖的package包/类
public static RenderedImage resizeImage(RenderedImage image, int width, int height)
      throws InconsistentImageScale
{
   RenderedImage resizedImage=image;
   // Computes ratio and scale
   float scale=getScale(image.getWidth(),image.getHeight(),width,height);
   
   // Processing resize process
   ParameterBlock pb = new ParameterBlock();
   // The source image
   pb.addSource(resizedImage);
   // The xScale
   pb.add(scale);
   // The yScale
   pb.add(scale);
   // The x translation
   pb.add(0.0F);
   // The y translation
   pb.add(0.0F);
   // The interpolation
   pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
   resizedImage = JAI.create("scale", pb, null);
   
   LOGGER.debug("Image resized to : " + resizedImage.getWidth() + "x"
      + resizedImage.getHeight());
   
   return resizedImage;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:29,代码来源:ProcessingUtils.java

示例13: toRenderedImage

import java.awt.image.RenderedImage; //导入依赖的package包/类
public static RenderedImage toRenderedImage(final Image img) {
	if (img instanceof RenderedImage)
		return (RenderedImage) img;
	final int savedSize = 64;
	final BufferedImage b = new BufferedImage(savedSize, savedSize, BufferedImage.TYPE_INT_ARGB);
	final Graphics2D g = b.createGraphics();
	g.drawImage(img, 0, 0, savedSize, savedSize, null);
	g.dispose();
	return b;
}
 
开发者ID:Njol,项目名称:Motunautr,代码行数:11,代码来源:FileIcon.java

示例14: imageToDataString

import java.awt.image.RenderedImage; //导入依赖的package包/类
static String imageToDataString(RenderedImage image) {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", bout);
    } catch (IOException e) {
        throw new UncheckedIOException("Not possible", e);
    }

    byte[] data = bout.toByteArray();
    byte[] base64 = Base64.getEncoder().encode(data);
    return "data:image/png;base64," + new String(base64, StandardCharsets.UTF_8);
}
 
开发者ID:andylizi,项目名称:ColorMOTD,代码行数:13,代码来源:MotdServerIcon.java

示例15: doWrite

import java.awt.image.RenderedImage; //导入依赖的package包/类
/**
 * Writes image to output stream  using given image writer.
 */
private static boolean doWrite(RenderedImage im, ImageWriter writer,
                             ImageOutputStream output) throws IOException {
    if (writer == null) {
        return false;
    }
    writer.setOutput(output);
    try {
        writer.write(im);
    } finally {
        writer.dispose();
        output.flush();
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ImageIO.java


注:本文中的java.awt.image.RenderedImage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。