• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ImageDecoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSelectedTiffFile

import com.sun.media.jai.codec.ImageDecoder; //导入依赖的package包/类
/**
 * The <code>getSelectedTiffFile</code> method is used to limit the file
 * to the page limit given.
 * 
 * @param tiffFile {@link File} tiff file from which limit has to be applied
 * @param pageLimit int
 * @throws IOException if file is not found
 */
public static void getSelectedTiffFile(final File tiffFile, final int pageLimit) throws IOException {
	OutputStream out = null;
	File newTiffFile = null;
	if (null != tiffFile && getTIFFPageCount(tiffFile.getAbsolutePath()) > pageLimit) {
		try {
			final List<BufferedImage> imageList = new ArrayList<BufferedImage>();
			final SeekableStream seekableStream = new FileSeekableStream(tiffFile);
			final ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", seekableStream, null);
			for (int i = 1; i < pageLimit; i++) {
				final PlanarImage planarImage = new NullOpImage(decoder.decodeAsRenderedImage(i), null, null, OpImage.OP_IO_BOUND);
				imageList.add(planarImage.getAsBufferedImage());
			}
			seekableStream.close();
			final TIFFEncodeParam params = new TIFFEncodeParam();
			params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
			String name = tiffFile.getName();
			final int indexOf = name.lastIndexOf(IUtilCommonConstants.DOT);
			name = name.substring(0, indexOf);
			final String finalPath = tiffFile.getParent() + File.separator + name
					+ System.currentTimeMillis() + IUtilCommonConstants.EXTENSION_TIF;
			newTiffFile = new File(finalPath);
			out = new FileOutputStream(finalPath); 
			final ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", out, params);
            params.setExtraImages(imageList.iterator()); 
            encoder.encode(imageList.get(0));
		} finally {
			if (null != out) {
				out.flush();
				out.close();
			}
		}
           if (tiffFile.delete() && null != newTiffFile) {
           	newTiffFile.renameTo(tiffFile);
		} else {
			if (null != newTiffFile) {
				newTiffFile.delete();
			}
		}
	}
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:49,代码来源:TIFFUtil.java


示例2: convertTiff

import com.sun.media.jai.codec.ImageDecoder; //导入依赖的package包/类
private void convertTiff(ByteArrayOutputStream outputStream, ByteArrayInputStream inStream) throws IOException, DocumentException, BadElementException, MalformedURLException 
{
	TIFFDecodeParam param = null;
	ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", inStream, param);	
	System.out.println("Convert TIFF file: Found " + decoder.getNumPages() + " pages");
	
	ArrayList<ByteArrayOutputStream> imagesStream = new ArrayList<ByteArrayOutputStream>();
	
	int pages = decoder.getNumPages();
	for (int i = 0; i < pages; i++) 
	{
		RenderedImage render = decoder.decodeAsRenderedImage(i);
		PlanarImage op = new NullOpImage(render, null, null, OpImage.OP_IO_BOUND);
		BufferedImage imageBuffer = op.getAsBufferedImage();
		
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		ImageIO.write(imageBuffer, "jpg", os);
		
		imagesStream.add(os);
	}
	
	if (imagesStream.size() > 0)
	{						
		Document document = new Document(PageSize.A4.rotate());
		PdfWriter writer = PdfWriter.getInstance(document, outputStream);
		
		document.open();
		
		Iterator<ByteArrayOutputStream> iterator = imagesStream.iterator();
		while (iterator.hasNext()) 
	    {
			document.newPage();
			Image jpg = Image.getInstance(iterator.next().toByteArray());
			jpg.scaleAbsolute(document.getPageSize().getWidth(), document.getPageSize().getHeight());
			document.add(jpg);
			
		}
		
		document.close();
		writer.flush();
		writer.close();
	}
}
 
开发者ID:IMS-MAXIMS,项目名称:openMAXIMS,代码行数:44,代码来源:ConversionHelper.java


示例3: dimensionsJAI

import com.sun.media.jai.codec.ImageDecoder; //导入依赖的package包/类
private int[] dimensionsJAI(byte[] byImg, String sCodec)
  throws IOException, NullPointerException {

  int[] aRetVal = new int[2];

  RenderedImage oImg;
  ImageDecoder oDecoder;

  oDecoder = ImageCodec.createImageDecoder(sCodec, new ByteArrayInputStream(byImg), null);

  oImg = oDecoder.decodeAsRenderedImage();

  aRetVal[0] = oImg.getWidth();
  aRetVal[1] = oImg.getHeight();

  return aRetVal;
}
 
开发者ID:sergiomt,项目名称:zesped,代码行数:18,代码来源:Picture.java


示例4: drawJAIImage

import com.sun.media.jai.codec.ImageDecoder; //导入依赖的package包/类
private void drawJAIImage(String sCodec, InputStream imgSrc, OutputStream outStr, int iThumbWidth, int iThumbHeight, float fQuality)
  throws IOException, InterruptedException, NullPointerException, IllegalArgumentException {

  RenderedImage oRenderedImg;
  PlanarImage oPlI;
  RenderedOp oScI;
  ParameterBlock oBlk;
  ImageEncoder oImgEnc;
  ImageDecoder oDecoder;

  Log.out.debug("Begin Picture.drawJAIImage("+sCodec+","+String.valueOf(iThumbWidth)+","+String.valueOf(iThumbHeight)+")");
  
  oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(sCodec, imgSrc, null);

  oRenderedImg = oDecoder.decodeAsRenderedImage();

  if (sCodec.equals("gif")) {
    // Increase color depth to 16M RGB
    try {
      javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();

      ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                               new int[] {8,8,8}, false, false,
                                               Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
      layout.setColorModel(cm);
      layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
      RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
      ParameterBlockJAI pb = new ParameterBlockJAI( "format" );
      pb.addSource( oRenderedImg );
      oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
    } catch (IllegalArgumentException iae) {
    }
    // End increase color depth
  } // gif

  oPlI = PlanarImage.wrapRenderedImage(oRenderedImg);

  int iImageWidth = oPlI.getWidth();
  int iImageHeight = oPlI.getHeight();

  float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);

  float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);

  if (thumbRatio < imageRatio)
    iThumbHeight = (int)(iThumbWidth / imageRatio);
  else
    iThumbWidth = (int)(iThumbHeight * imageRatio);

  float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);

  float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);

  oBlk = new ParameterBlock();

  oBlk.addSource(oPlI);

  oBlk.add(scaleW);
  oBlk.add(scaleH);
  oBlk.add(0.0f);
  oBlk.add(0.0f);
  oBlk.add(new javax.media.jai.InterpolationBilinear());

  oScI = JAI.create("scale", oBlk, null); // scale image NOW !
  		
  oImgEnc = ImageCodec.createImageEncoder( "jpeg", outStr, null );
 
  if (null==oImgEnc) {
    throw new NullPointerException("Cannot create ImageEncoder for jpeg");
  }
  else {
    oImgEnc.encode( oScI ); // write encoded data to given output stream
    oImgEnc =null;
  }

  Log.out.debug("End Picture.drawJAIImage()");

}
 
开发者ID:sergiomt,项目名称:zesped,代码行数:79,代码来源:Picture.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Im类代码示例发布时间:2022-05-23
下一篇:
Java SuperActivityToast类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap