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


Java ImageReadParam.setSourceRegion方法代码示例

本文整理汇总了Java中javax.imageio.ImageReadParam.setSourceRegion方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReadParam.setSourceRegion方法的具体用法?Java ImageReadParam.setSourceRegion怎么用?Java ImageReadParam.setSourceRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.ImageReadParam的用法示例。


在下文中一共展示了ImageReadParam.setSourceRegion方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: call

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Override
public ImagePartLoader call() throws Exception {
    Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
    try (ImageInputStream stream = ImageIO.createImageInputStream(file);) {
        Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
        if (readers.hasNext()) {
            ImageReader reader = readers.next();
            reader.setInput(stream, true, true);
            ImageReadParam param = reader.getDefaultReadParam();
            param.setSourceRegion(region);
            BufferedImage part = reader.read(0, param);
            Raster source = part.getRaster();
            WritableRaster target = image.getRaster();
            target.setRect(0, y, source);
        }
    }
    return ImagePartLoader.this;
}
 
开发者ID:DataSystemsLab,项目名称:GeoSpark,代码行数:19,代码来源:BigBufferedImage.java

示例8: call

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Override
public ImagePartLoader call() throws Exception {
    Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
    ImageInputStream stream = ImageIO.createImageInputStream(file);
    Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
    if (readers.hasNext()) {
        ImageReader reader = readers.next();
        reader.setInput(stream, true, true);
        ImageReadParam param = reader.getDefaultReadParam();
        param.setSourceRegion(region);
        BufferedImage part = reader.read(0, param);
        Raster source = part.getRaster();
        WritableRaster target = image.getRaster();
        target.setRect(0, y, source);
    }
    return ImagePartLoader.this;
}
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:18,代码来源:BigBufferedImage.java

示例9: cut

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public void cut() throws IOException {
 FileInputStream is = null;
 ImageInputStream iis = null;
 try {
  is = new FileInputStream(srcpath);
  Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(this.imageType);
  ImageReader reader = it.next();
  iis = ImageIO.createImageInputStream(is);
  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);
  ImageIO.write(bi, this.imageType, new File(subpath));
 } finally {
  if (is != null)
   is.close();
  if (iis != null)
   iis.close();
 }
}
 
开发者ID:fixteam,项目名称:fixflow,代码行数:22,代码来源:ImageCutUtil.java

示例10: readTile

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public BufferedImage readTile(int imageIndex, int tileX, int tileY)
        throws IOException {

    int w = getWidth(imageIndex);
    int h = getHeight(imageIndex);
    int tw = getTileWidth(imageIndex);
    int th = getTileHeight(imageIndex);

    int x = tw * tileX;
    int y = th * tileY;

    if (tileX < 0 || tileY < 0 || x >= w || y >= h) {
        throw new IllegalArgumentException("Tile indices are out of bounds!");
    }

    if (x + tw > w) {
        tw = w - x;
    }

    if (y + th > h) {
        th = h - y;
    }

    ImageReadParam param = getDefaultReadParam();
    Rectangle tileRect = new Rectangle(x, y, tw, th);
    param.setSourceRegion(tileRect);

    return read(imageIndex, param);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:TIFFImageReader.java

示例11: test

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
private static void test(String format) throws IOException {
    System.out.println("Format: " + format);

    BufferedImage src = createSrc();

    ImageInputStream iis = prepareInput(src, format);

    ImageReader reader = ImageIO.getImageReaders(iis).next();

    reader.setInput(iis);

    ImageReadParam p = reader.getDefaultReadParam();
    int cnt = 0;
    do {
        System.out.println("cnt: " + cnt);
        p.setSourceRegion(new Rectangle(width / 4, height / 4,
                                        width / 2, height / 2));

        BufferedImage dst = reader.read(0, p);

        final Color c = new Color(dst.getRGB(10, 10), true);

        if (!sameColor(c, srcColor)) {
            throw new RuntimeException(
                String.format("Test failed: read color 0x%X\n",
                              c.getRGB()));
        }
    } while (++cnt < max);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:MultiReadTest.java

示例12: readTestImage

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public static BufferedImage readTestImage(String fileName,
                               BufferedImage dest,
                               Rectangle srcROI)
{
    BufferedImage bi = null;

    try {
        FileImageInputStream is =
            new FileImageInputStream(new File(fileName));
        ImageReader reader =
            (ImageReader)ImageIO.getImageReaders(is).next();
        ImageReadParam param = reader.getDefaultReadParam();
        if (dest != null) {
            param.setDestination(dest);
        }
        if (srcROI != null) {
            param.setSourceRegion(srcROI);
        }
        reader.setInput(is);
        bi = reader.read(0, param);
    } catch (IOException e) {
        System.err.println("Error " + e +
                           " when reading file: " + fileName);
        throw new RuntimeException(e);
    }

    return bi;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:JPEGsNotAcceleratedTest.java

示例13: testReadRegionAligned

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Test
public void testReadRegionAligned() throws IOException {
  ImageReader reader = getReader("crop_aligned.jpg");
  ImageReadParam param = reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(32, 32, 96, 96));
  BufferedImage img = reader.read(0, param);
  assertThat(img)
      .hasDimensions(96, 96)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:11,代码来源:TurboJpegImageReaderTest.java

示例14: testReadRegionUnaligned

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Test
public void testReadRegionUnaligned() throws IOException {
  ImageReader reader = getReader("crop_unaligned.jpg");
  ImageReadParam param = reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(116, 148, 204, 172));
  BufferedImage img = reader.read(0, param);
  assertThat(img)
      .hasDimensions(204, 172)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:11,代码来源:TurboJpegImageReaderTest.java

示例15: testReadUnalignedScaled

import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
@Test
public void testReadUnalignedScaled() throws IOException {
  ImageReader reader = getReader("crop_unaligned.jpg");
  ImageReadParam param = reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(87, 111, 152, 129));
  BufferedImage img = reader.read(1, param);
  assertThat(img)
      .hasDimensions(152, 129)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:11,代码来源:TurboJpegImageReaderTest.java


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