當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageReadParam類代碼示例

本文整理匯總了Java中javax.imageio.ImageReadParam的典型用法代碼示例。如果您正苦於以下問題:Java ImageReadParam類的具體用法?Java ImageReadParam怎麽用?Java ImageReadParam使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ImageReadParam類屬於javax.imageio包,在下文中一共展示了ImageReadParam類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cut

import javax.imageio.ImageReadParam; //導入依賴的package包/類
public static BufferedImage cut(String format, InputStream src, int x, int y, int w, int h) throws IOException {
	Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName(format);
	ImageReader reader = (ImageReader) iterator.next();
	ImageInputStream iis = ImageIO.createImageInputStream(src);
	reader.setInput(iis, true);
	ImageReadParam param = reader.getDefaultReadParam();
	int imgWidth = reader.getWidth(0);
	int imgHeight = reader.getHeight(0);
	if (x + w > imgWidth) {
		w = imgWidth - x;
	}
	if (y + h > imgHeight) {
		h = imgHeight - y;
	}
	Rectangle rect = new Rectangle(x, y, w, h);
	param.setSourceRegion(rect);
	BufferedImage bi = reader.read(0, param);
	return bi;
}
 
開發者ID:szsucok,項目名稱:sucok-framework,代碼行數:20,代碼來源:ImageSizeUtils.java

示例2: newData

import javax.imageio.ImageReadParam; //導入依賴的package包/類
@Override
public void newData(byte[] bytes) {
	if(Dashboard.visionInitialized()){
		Mat m = CvProcessing.byteArray2Mat(bytes);
		Dashboard.setForVision(m);
	}
	if(mode == DisplayMode.Normal){
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpeg");
 
        ImageReader reader = (ImageReader) readers.next();
        Object source = bis; 
       
		try {
			ImageInputStream iis = ImageIO.createImageInputStream(source); 
		    reader.setInput(iis, true);
		    ImageReadParam param = reader.getDefaultReadParam();
		    BufferedImage image = reader.read(0, param); 
		    setImage(image);
		} catch (IOException e) {
		}
	}

}
 
開發者ID:Flash3388,項目名稱:FlashLib,代碼行數:25,代碼來源:CameraViewer.java

示例3: TIFFRenderedImage

import javax.imageio.ImageReadParam; //導入依賴的package包/類
public TIFFRenderedImage(TIFFImageReader reader,
                         int imageIndex,
                         ImageReadParam readParam,
                         int width, int height) throws IOException {
    this.reader = reader;
    this.imageIndex = imageIndex;
    this.tileParam = cloneImageReadParam(readParam, false);

    this.subsampleX = tileParam.getSourceXSubsampling();
    this.subsampleY = tileParam.getSourceYSubsampling();

    this.isSubsampling = this.subsampleX != 1 || this.subsampleY != 1;

    this.width = width/subsampleX;
    this.height = height/subsampleY;

    // If subsampling is being used, we may not match the
    // true tile grid exactly, but everything should still work
    this.tileWidth = reader.getTileWidth(imageIndex)/subsampleX;
    this.tileHeight = reader.getTileHeight(imageIndex)/subsampleY;

    Iterator<ImageTypeSpecifier> iter = reader.getImageTypes(imageIndex);
    this.its = iter.next();
    tileParam.setDestinationType(its);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TIFFRenderedImage.java

示例4: read

import javax.imageio.ImageReadParam; //導入依賴的package包/類
public BufferedImage read(int imageIndex, ImageReadParam param)
                        throws IOException {
    checkState(imageIndex);
    int len = 3*width*height;
    byte[] imageData = new byte[len];
    // The following is not efficient and is skipping all the
    // progress updates, and ignoring the ImageReadParam, which
    // it should not, but it is all we need for this test.
    stream.readFully(imageData, 0, len);
    BufferedImage bi =
        new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int off = 0;
    for (int h=0;h<height;h++) {
        int rgb = imageData[off]++ << 16 |
                  imageData[off++] <<  8 | imageData[off++];
        for (int w=0;w<width;w++) {
            bi.setRGB(w, h, rgb);
        }
    }
    return bi;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:SIMPImageReader.java

示例5: readTile

import javax.imageio.ImageReadParam; //導入依賴的package包/類
@Override
public BufferedImage readTile(int imageIndex, int tileX, int tileY) throws IOException {
  checkIndex(imageIndex);
  int xOffset = getTileGridXOffset(imageIndex);
  int yOffset = getTileGridYOffset(imageIndex);
  int tileWidth = getTileWidth(imageIndex);
  int tileHeight = getTileHeight(imageIndex);
  Rectangle region = new Rectangle(
      xOffset + tileX * tileWidth,
      yOffset + tileY * tileHeight,
      tileWidth,
      tileHeight);
  if (region.x + region.width > getWidth(imageIndex) || region.y + region.height > getHeight(imageIndex)) {
    throw new IllegalArgumentException("Tile indices out of bounds.");
  }
  ImageReadParam param = getDefaultReadParam();
  param.setSourceRegion(region);
  return this.read(imageIndex, param);
}
 
開發者ID:dbmdz,項目名稱:imageio-jnr,代碼行數:20,代碼來源:OpenJp2ImageReader.java

示例6: readImage

import javax.imageio.ImageReadParam; //導入依賴的package包/類
public static BufferedImage readImage(Object source) throws IOException
{
	ImageInputStream stream = ImageIO.createImageInputStream(source);
	ImageReader reader = ImageIO.getImageReaders(stream).next();
	reader.setInput(stream);
	ImageReadParam param =reader.getDefaultReadParam();

	ImageTypeSpecifier typeToUse = null;
	for (Iterator i = reader.getImageTypes(0);i.hasNext(); )
	{
		ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
		if (type.getColorModel().getColorSpace().isCS_sRGB())
			typeToUse = type;
	}
	if (typeToUse!=null) param.setDestinationType(typeToUse);

	BufferedImage b = reader.read(0, param);
	reader.dispose();
	stream.close();
	return b;
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:22,代碼來源:MapUtil.java

示例7: getReadParam

import javax.imageio.ImageReadParam; //導入依賴的package包/類
/** Determine parameters for image reading based on the IIIF selector and a given scaling factor **/
private ImageReadParam getReadParam(ImageReader reader, ImageApiSelector selector, double decodeScaleFactor) throws IOException {
  ImageReadParam readParam = reader.getDefaultReadParam();
  Dimension nativeDimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
  Rectangle targetRegion = selector.getRegion().resolve(nativeDimensions);
  // IIIF regions are always relative to the native size, while ImageIO regions are always relative to the decoded
  // image size, hence the conversion
  Rectangle decodeRegion = new Rectangle(
          (int) Math.ceil(targetRegion.getX() * decodeScaleFactor),
          (int) Math.ceil(targetRegion.getY() * decodeScaleFactor),
          (int) Math.ceil(targetRegion.getWidth() * decodeScaleFactor),
          (int) Math.ceil(targetRegion.getHeight() * decodeScaleFactor));
  readParam.setSourceRegion(decodeRegion);

  // TurboJpegImageReader can rotate during decoding
  boolean didRotate = false;
  if (selector.getRotation().getRotation() != 0 && reader instanceof TurboJpegImageReader) {
    ((TurboJpegImageReadParam) readParam).setRotationDegree((int) selector.getRotation().getRotation());
    didRotate = true;
  }
  return readParam;
}
 
開發者ID:dbmdz,項目名稱:iiif-server-hymir,代碼行數:23,代碼來源:ImageServiceImpl.java

示例8: read

import javax.imageio.ImageReadParam; //導入依賴的package包/類
private static LoadedImage read(ImageInputStream stream, ImageType imageType) throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }

    Iterator iter = ImageIO.getImageReaders(stream);
    if (!iter.hasNext()) {
        return null;
    }

    ImageReader reader = (ImageReader) iter.next();
    ImageReadParam param = reader.getDefaultReadParam();
    reader.setInput(stream, true, true);
    BufferedImage bi;
    IIOMetadata metadata;
    try {
        metadata = reader.getImageMetadata(0);
        bi = reader.read(0, param);
    } finally {
        reader.dispose();
        stream.close();
    }

    return new LoadedImage(null, bi, metadata, null);
}
 
開發者ID:patrickfav,項目名稱:density-converter,代碼行數:26,代碼來源:ImageUtil.java

示例9: readSvg

import javax.imageio.ImageReadParam; //導入依賴的package包/類
@Deprecated
public static BufferedImage readSvg(File file, Dimension sourceDimension) throws Exception {
    try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
        Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
        if (!readers.hasNext()) {
            throw new IllegalArgumentException("No reader for: " + file);
        }

        ImageReader reader = readers.next();
        try {
            reader.setInput(input);
            ImageReadParam param = reader.getDefaultReadParam();
            param.setSourceRenderSize(sourceDimension);
            return reader.read(0, param);
        } finally {
            reader.dispose();
        }
    }
}
 
開發者ID:patrickfav,項目名稱:density-converter,代碼行數:20,代碼來源:ImageUtil.java

示例10: cutImage

import javax.imageio.ImageReadParam; //導入依賴的package包/類
/**
 * @Description:截圖
 * @author:liuyc
 * @time:2016年5月27日 上午10:18:23
 * @param srcFile源圖片、targetFile截好後圖片全名、startAcross 開始截取位置橫坐標、StartEndlong開始截圖位置縱坐標、width截取的長,hight截取的高
 */
public static void cutImage(String srcFile, String targetFile, int startAcross, int StartEndlong, int width,
		int hight) throws Exception {
	// 取得圖片讀入器
	Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpg");
	ImageReader reader = readers.next();
	// 取得圖片讀入流
	InputStream source = new FileInputStream(srcFile);
	ImageInputStream iis = ImageIO.createImageInputStream(source);
	reader.setInput(iis, true);
	// 圖片參數對象
	ImageReadParam param = reader.getDefaultReadParam();
	Rectangle rect = new Rectangle(startAcross, StartEndlong, width, hight);
	param.setSourceRegion(rect);
	BufferedImage bi = reader.read(0, param);
	ImageIO.write(bi, targetFile.split("\\.")[1], new File(targetFile));
}
 
開發者ID:xiaomin0322,項目名稱:alimama,代碼行數:23,代碼來源:ImageHandleHelper.java

示例11: getBufferedImages

import javax.imageio.ImageReadParam; //導入依賴的package包/類
private List<BufferedImage> getBufferedImages(byte[] favIconBytes) throws IOException {
	try (ImageInputStream stream = ImageIO.createImageInputStream(new ByteArrayInputStream(favIconBytes))) {
		Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);
		if (!iter.hasNext()) {
			return Collections.emptyList();
		}
		ImageReader reader = (ImageReader) iter.next();
		try {
			ImageReadParam param = reader.getDefaultReadParam();
			reader.setInput(stream, true, true);
			List<BufferedImage> bufferedImages = new ArrayList<>();
			int i = 0;
			while (true) {
				try {
					BufferedImage bufferedImage = reader.read(i, param);
					bufferedImages.add(bufferedImage);
				} catch (IndexOutOfBoundsException e) {
					return bufferedImages;
				}
				i++;
			}
		} finally {
			reader.dispose();
		}
	}
}
 
開發者ID:cchabanois,項目名稱:mesfavoris,代碼行數:27,代碼來源:UrlBookmarkPropertiesProvider.java

示例12: readBuffereImage

import javax.imageio.ImageReadParam; //導入依賴的package包/類
private static BufferedImage readBuffereImage(ImageReader reader, int w, int h) throws IOException {
	ImageReadParam param = reader.getDefaultReadParam();
	int srcWidth = reader.getWidth(0);
	int srcHeight = reader.getHeight(0);

	Rectangle rect = null;

	if (w / h > srcWidth / srcHeight) {
		h = h * srcWidth / w;
		w = srcWidth;
		rect = new Rectangle(0, (srcHeight - h) / 2, w, h);
	} else {
		w = w * srcHeight / h;
		h = srcHeight;
		rect = new Rectangle((srcWidth - w) / 2, 0, w, h);
	}
	param.setSourceRegion(rect);
	BufferedImage srcBuffered = reader.read(0, param);
	return srcBuffered;
}
 
開發者ID:lusparioTT,項目名稱:OooO,代碼行數:21,代碼來源:ImageUtils.java

示例13: readImageFromBytes

import javax.imageio.ImageReadParam; //導入依賴的package包/類
@NotNull
public static BufferedImage readImageFromBytes(@NotNull byte[] content) throws IOException {
  InputStream inputStream = new ByteArrayInputStream(content, 0, content.length);
  ImageInputStream imageInputStream = ImageIO.createImageInputStream(inputStream);
  try {
    Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
    if (imageReaders.hasNext()) {
      ImageReader imageReader = imageReaders.next();
      try {
        ImageReadParam param = imageReader.getDefaultReadParam();
        imageReader.setInput(imageInputStream, true, true);
        int minIndex = imageReader.getMinIndex();
        return imageReader.read(minIndex, param);
      }
      finally {
        imageReader.dispose();
      }
    }
  }
  finally {
    imageInputStream.close();
  }
  throw new IOException("Can't read image from given content");
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:ImagePreviewComponent.java

示例14: ByteArrayInputStream

import javax.imageio.ImageReadParam; //導入依賴的package包/類
/**
 * 方法(私有)<br>
 * 名稱:    cropImage<br>
 * 描述:    根據指定的位置和尺寸剪切圖片<br>
 *
 * @return BufferedImage - 圖片字節數組
 * @throws java.io.IOException
 */
private ByteArrayOutputStream cropImage
(ByteArrayOutputStream out,int x,int y,int width,int height)
        throws IOException
{
    Iterator iterator=ImageIO.getImageReadersByFormatName(this.outputFormat.getFormat());
    ImageReader reader=(ImageReader)iterator.next();
    InputStream in=new ByteArrayInputStream(out.toByteArray());
    ImageInputStream iis=ImageIO.createImageInputStream(in);
    reader.setInput(iis,true);
    ImageReadParam param=reader.getDefaultReadParam();
    Rectangle rect=new Rectangle(x,y,width,height);
    param.setSourceRegion(rect);
    BufferedImage bi=reader.read(0,param);
    out.reset();
    ImageIO.write(bi,this.outputFormat.getFormat(),out);
    //System.out.println("dropImage:"+out.toByteArray().length);
    return out;
}
 
開發者ID:ProteanBear,項目名稱:ProteanBear_Java,代碼行數:27,代碼來源:ImageProcessor.java

示例15: checkImageReadParam

import javax.imageio.ImageReadParam; //導入依賴的package包/類
/**
 * <p>
 * Validate that the specified {@link javax.imageio.ImageReadParam} contains
 * only the default values. If non-default values are present,
 * {@link java.io.IOException} is thrown.
 * </p>
 * 
 * @param param
 *            the <code>ImageReadParam</code> to be validated
 * @param head
 *            the <code>TGAHeader</code> that contains information about the
 *            source image
 * @throws IOException
 *             if the <code>ImageReadParam</code> contains non-default
 *             values
 */
private void checkImageReadParam(final ImageReadParam param, final TGAHeader header) throws IOException {
	if (param != null) {
		// get the image height and width from the header for convenience
		final int width = header.getWidth();
		final int height = header.getHeight();

		// ensure that the param contains only the defaults
		final Rectangle sourceROI = param.getSourceRegion();
		if ((sourceROI != null) && ((sourceROI.x != 0) || (sourceROI.y != 0) || (sourceROI.width != width) || (sourceROI.height != height))) {
			throw new IOException("The source region of interest is not the default."); // FIXME:
																						// localize
		} /* else -- the source ROI is the default */

		final Rectangle destinationROI = param.getSourceRegion();
		if ((destinationROI != null) && ((destinationROI.x != 0) || (destinationROI.y != 0) || (destinationROI.width != width) || (destinationROI.height != height))) {
			throw new IOException("The destination region of interest is not the default."); // FIXME:
																								// localize
		} /* else -- the destination ROI is the default */

		if ((param.getSourceXSubsampling() != 1) || (param.getSourceYSubsampling() != 1)) {
			throw new IOException("Source sub-sampling is not supported."); // FIXME:
																			// localize
		} /* else -- sub-sampling is the default */
	} /* else -- the ImageReadParam is null so the defaults *are* used */
}
 
開發者ID:xtremexp,項目名稱:UT4Converter,代碼行數:42,代碼來源:TGAImageReader.java


注:本文中的javax.imageio.ImageReadParam類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。