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


Java JPEGEncodeParam类代码示例

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


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

示例1: saveToDisk

import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public void saveToDisk(TiledImage ti, String fn) throws IOException {
    BufferedImage buffImg = new BufferedImage(ti.getWidth(), ti.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics g2d = buffImg.getGraphics();
    g2d.drawImage(ti.getAsBufferedImage(), 0, 0, null);
    buffImg.flush();

    JPEGEncodeParam jpgParam = new JPEGEncodeParam();
    jpgParam.setQuality(0.85f);
    JAI.create("filestore", buffImg, fn, "JPEG", jpgParam);
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:11,代码来源:ClassImageRenderer.java

示例2: getEncoder

import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
  final JPEGEncodeParam param = new JPEGEncodeParam();
  param.setQuality(1f);
  return com.sun.media.jai.codec.ImageCodec.createImageEncoder("JPEG", out, param); //$NON-NLS-1$
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:7,代码来源:JpegEncoder.java

示例3: saveCurrentView

import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
/**
 * stores the current viewport as an image file. Executes a fileChooser for choosing the file and
 * displays a JOptionPane if successful.
 */
public void saveCurrentView() {
    JFileChooser fc = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("*.jpg", "jpg");
    fc.setFileFilter(filter);
    String snapShotFileName = recognitionFrame.getPicName();
    snapShotFileName = snapShotFileName.replaceAll(RawUtilsCommon.getExtension(snapShotFileName, false), "snapshot.jpg");
    fc.setSelectedFile(new File(snapShotFileName));
    int returnVal = fc.showSaveDialog(this);
    String fn = null;
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        fn = fc.getSelectedFile().getAbsolutePath();
        if (!fn.toLowerCase().endsWith(".jpg")) fn += ".jpg";
    }
    fc = null;
    this.repaint();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    if (fn != null) {
        BufferedImage bi;
        Robot robot;
        try {
            Rectangle r = recognitionFrame.getBounds();
            r.x += recognitionFrame.getLocationOnScreen().x;
            r.y += recognitionFrame.getLocationOnScreen().y;
            robot = new Robot();
            bi = robot.createScreenCapture(r);
            JPEGEncodeParam jpgParam = new JPEGEncodeParam();
            jpgParam.setQuality(0.85f);
            JAI.create("filestore", bi, fn, "JPEG", jpgParam);
            System.gc(); // forces JAI to close the filehandle
            logger.debug("finished writing");
            JOptionPane.showMessageDialog(this, "Screenshot successfully saved to " + fn, "Screenshot saved", JOptionPane.INFORMATION_MESSAGE);
        } catch (AWTException e) {
            logger.error("error saving screenshot", e);
        }
    }
}
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:45,代码来源:ImageFrame.java

示例4: makeImageSnapshot

import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public void makeImageSnapshot() {
     if (((long) bimg.getWidth() * bimg.getHeight()) > (8000L * 8000L)) {
         JOptionPane.showMessageDialog(this, "In the current version this feature can only be used for images where width*height <= 8000*8000.\nHowever, you can use the Orbit Agent to download the file.", "Image too large", JOptionPane.ERROR_MESSAGE);
         return;
     }

     JFileChooser fc = new JFileChooser();
     FileNameExtensionFilter filter = new FileNameExtensionFilter("*.tif", "tif");
     fc.setFileFilter(filter);
     String snapShotFileName = getPicName();
     snapShotFileName = snapShotFileName.replaceAll(RawUtilsCommon.getExtension(snapShotFileName, false), "tif");
     fc.setSelectedFile(new File(snapShotFileName));

     int returnVal = fc.showSaveDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {

         logger.debug("begin making image snapshot");
         String fn = fc.getSelectedFile().getAbsolutePath();
         if (!fn.toLowerCase().endsWith(".tif")) fn += ".tif";

         Dimension2D oldVPSize = viewPortSize;
         Point2D oldVPOffs = getViewPortOffset();
         double sc = getScale();
         setScale(100d);
         setViewPortOffset(new Point(0, 0));
         viewPortSize = new Dimension(bimg.getWidth(), bimg.getHeight());
		
/*
ColorModel colorModel = new ComponentColorModel(
		 ColorSpace.getInstance(ColorSpace.CS_sRGB),
		 new int[]{8,8,8}, false, false,
		 Transparency.OPAQUE, 
		 DataBuffer.TYPE_BYTE); 
SampleModel sampleModel = colorModel.createCompatibleSampleModel(256, 256);
DiskMemImage tiledImage = new DiskMemImage(0, 0, bimg.getWidth(), bimg.getHeight(), 0, 0, sampleModel, colorModel);
Graphics2D g2d = (Graphics2D)tiledImage.createGraphics();
((DiskMemImageGraphics)g2d).overwriteRenderingHint((((Graphics2D)getGraphics()).getRenderingHints()));
*/
         // Update 1.7.2010: Fallback to normal bufferedImage (only up to 30kx30k pixel!)
         // due to rendering problems with class image (only first tile problem)

         BufferedImage buffImg = new BufferedImage(bimg.getWidth(), bimg.getHeight(), BufferedImage.TYPE_INT_RGB);
         Graphics2D g2d = buffImg.createGraphics();
         buffImg.flush();


         paint(g2d);
         setScale(sc);
         setViewPortOffset(oldVPOffs);
         viewPortSize = oldVPSize;
         logger.info("finished painting");

         TIFFEncodeParam param = new TIFFEncodeParam();
         param.setTileSize(128, 128);
         param.setWriteTiled(true);
         param.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
         JPEGEncodeParam jpgParam = new JPEGEncodeParam();
         jpgParam.setQuality(0.85f);
         param.setJPEGEncodeParam(jpgParam);

         // TODO: extraImages (Iterator where .next() returns further (low-res) RenderedImages
         //param.setExtraImages(extraImages)

         JAI.create("filestore", /*tiledImage*/buffImg, fn, "TIFF", param);

         logger.info("finished writing");

         JOptionPane.showMessageDialog(null, "Image successfully saved to " + fn, "Image saved", JOptionPane.INFORMATION_MESSAGE);

         //tiledImage = null;
         //DiskMemImage.getCommonTileCache().flush();
         Runtime.getRuntime().gc();
         Runtime.getRuntime().gc();
         Runtime.getRuntime().gc();
         logger.debug("cleaning up finished");

     }

 }
 
开发者ID:mstritt,项目名称:orbit-image-analysis,代码行数:80,代码来源:RecognitionFrame.java

示例5: convertPdfToImage

import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public static void convertPdfToImage(File file, String createPath, int type)
		throws Exception {
	@SuppressWarnings("resource")
	FileChannel channel = new RandomAccessFile(file, "r").getChannel();
	MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0,
			channel.size());
	PDFFile pdffile = new PDFFile(buf);

	for (int i = 1; i <= pdffile.getNumPages(); i++) {
		PDFPage page = pdffile.getPage(i);
		Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()
				.getWidth(), (int) page.getBBox().getHeight());
		Image img = page.getImage(rect.width, rect.height, rect, null,
				true, true);

		BufferedImage tag = new BufferedImage(rect.width, rect.height,
				BufferedImage.TYPE_INT_RGB);
		tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,
				null);

		String fileName = createPath
				+ "\\"
				+ file.getName().substring(0,
						file.getName().lastIndexOf('.'));
		FileOutputStream out = null;
		ImageEncoder enc = null;
		switch (type) {
		case ImageType.TYPE_JPEG:
			out = new FileOutputStream(fileName + i + ".jpg");
			enc = ImageCodec.createImageEncoder("jpeg", out,
					new JPEGEncodeParam());
			break;
		case ImageType.TYPE_TIFF:
			out = new FileOutputStream(fileName + i + ".tif");
			enc = ImageCodec.createImageEncoder("tiff", out,
					new TIFFEncodeParam());
			break;
		}
		if (null != out && null != enc) {
			enc.encode(tag);
			out.close();
		}

	}
}
 
开发者ID:joaquinaimar,项目名称:wizard,代码行数:46,代码来源:ImageCodeUtil.java


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