public static boolean writeJPG(File file, RenderedImage source, float quality) { if (file.exists() && !file.canWrite()) { return false; } try (OutputStream os = new FileOutputStream(file)) { writeJPG(os, source, quality); } catch (OutOfMemoryError | IOException e) { LOGGER.error("", e); //$NON-NLS-1$ return false; } return true; }
private PlanarImage readImageIOImage(File file) throws IOException { ImageReader reader = getDefaultReader(mimeType); if (reader == null) { LOGGER.info("Cannot find a reader for the mime type: {}", mimeType); //$NON-NLS-1$ return null; } ImageInputStream stream = new FileImageInputStream(new RandomAccessFile(file, "r")); //$NON-NLS-1$ ImageReadParam param = reader.getDefaultReadParam(); reader.setInput(stream, true, true); RenderedImage bi; try { bi = reader.read(0, param); } finally { reader.dispose(); stream.close(); } // to avoid problem with alpha channel and png encoded in 24 and 32 bits bi = ImageFiler.getReadableImage(bi); return ImageConversion.toMat(bi); }
@Override public void run() { PlanarImage img = null; // Get the final that contain the thumbnail when the uncompress mode is activated File file = diskObject.getFile(); if (file != null && file.getName().endsWith(".wcv")) { //$NON-NLS-1$ File thumbFile = new File(ImageFiler.changeExtension(file.getPath(), ".jpg")); //$NON-NLS-1$ if (thumbFile.canRead()) { img = ImageProcessor.readImage(thumbFile); } } if (img == null) { img = diskObject.getRenderedImage(diskObject.getImage(null)); } if (img == null) { return; } final BufferedImage tIcon = ImageConversion .toBufferedImage((PlanarImage) ImageProcessor.buildThumbnail(img, ThumbnailRenderer.ICON_DIM, true)); // Prevent to many files open on Linux (Ubuntu => 1024) and close image stream diskObject.removeImageFromCache(); GuiExecutor.instance().execute(() -> { if (tIcon != null) { cachedThumbnails.put(diskObject.getMediaURI(), new ThumbnailIcon(tIcon)); } thumbnailList.getThumbnailListModel().notifyAsUpdated(index); }); }
private PlanarImage getValidImage(RenderedImage buffer, MediaElement media) { PlanarImage img = null; if (buffer != null) { RenderedImage image = ImageFiler.getReadableImage(buffer);
new File(ImageFiler.changeExtension(outFile.getPath(), ".jpg")), Thumbnail.MAX_SIZE); //$NON-NLS-1$ return outFile; } catch (Exception e) {