當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。