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


Java Raster.getNumBands方法代码示例

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


在下文中一共展示了Raster.getNumBands方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeIDAT

import java.awt.image.Raster; //导入方法依赖的package包/类
private void writeIDAT() throws IOException
{
	IDATOutputStream ios = new IDATOutputStream(dataOutput, 8192);
	DeflaterOutputStream dos = new DeflaterOutputStream(ios,
			new Deflater(9));

	// Future work - don't convert entire image to a Raster It
	// might seem that you could just call image.getData() but
	// 'BufferedImage.subImage' doesn't appear to set the Width
	// and height properly of the Child Raster, so the Raster
	// you get back here appears larger than it should.
	// This solves that problem by bounding the raster to the
	// image's bounds...
	Raster ras = image.getData(new Rectangle(image.getMinX(), image
			.getMinY(), image.getWidth(), image.getHeight()));
	// System.out.println("Image: [" +
	//                    image.getMinY()  + ", " +
	//                    image.getMinX()  + ", " +
	//                    image.getWidth()  + ", " +
	//                    image.getHeight() + "]");
	// System.out.println("Ras: [" +
	//                    ras.getMinX()  + ", " +
	//                    ras.getMinY()  + ", " +
	//                    ras.getWidth()  + ", " +
	//                    ras.getHeight() + "]");

	if (skipAlpha)
	{
		int numBands = ras.getNumBands() - 1;
		int[] bandList = new int[numBands];
		for (int i = 0; i < numBands; i++)
		{
			bandList[i] = i;
		}
		ras = ras.createChild(0, 0, ras.getWidth(), ras.getHeight(), 0, 0,
				bandList);
	}

	if (interlace)
	{
		// Interlacing pass 1
		encodePass(dos, ras, 0, 0, 8, 8);
		// Interlacing pass 2
		encodePass(dos, ras, 4, 0, 8, 8);
		// Interlacing pass 3
		encodePass(dos, ras, 0, 4, 4, 8);
		// Interlacing pass 4
		encodePass(dos, ras, 2, 0, 4, 4);
		// Interlacing pass 5
		encodePass(dos, ras, 0, 2, 2, 4);
		// Interlacing pass 6
		encodePass(dos, ras, 1, 0, 2, 2);
		// Interlacing pass 7
		encodePass(dos, ras, 0, 1, 1, 2);
	}
	else
	{
		encodePass(dos, ras, 0, 0, 1, 1);
	}

	dos.finish();
	ios.flush();
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:64,代码来源:mxPngImageEncoder.java

示例2: encode

import java.awt.image.Raster; //导入方法依赖的package包/类
/** Encode an image to JPEG **/
public ByteBuffer encode(Raster img, int quality) throws TurboJpegException {
  Pointer codec = null;
  Pointer bufPtr = null;
  try {
    TJPF pixelFmt;
    switch (img.getNumBands()) {
      case 4:
        pixelFmt = TJPF.TJPF_BGRX; // 4BYTE_BGRA
        break;
      case 3:
        pixelFmt = TJPF.TJPF_BGR;  // 3BYTE_BGR
        break;
      case 1:
        pixelFmt = TJPF.TJPF_GRAY; // 1BYTE_GRAY
        break;
      default:
        throw new IllegalArgumentException("Illegal sample format");
    }
    TJSAMP sampling = pixelFmt == TJPF.TJPF_GRAY ? TJSAMP.TJSAMP_GRAY : TJSAMP.TJSAMP_444;
    codec = lib.tjInitCompress();

    // Allocate JPEG target buffer
    int bufSize = (int) lib.tjBufSize(img.getWidth(), img.getHeight(), sampling);
    bufPtr = lib.tjAlloc(bufSize);
    NativeLongByReference lenPtr = new NativeLongByReference(bufSize);

    // Wrap source image data buffer with ByteBuffer to pass it over the ABI
    ByteBuffer inBuf = ByteBuffer.wrap(((DataBufferByte) img.getDataBuffer()).getData())
        .order(runtime.byteOrder());
    int rv = lib.tjCompress2(
        codec, inBuf, img.getWidth(), 0, img.getHeight(),  pixelFmt,
        new PointerByReference(bufPtr), lenPtr, sampling, quality, 0);
    if (rv != 0) {
      LOG.error("Could not compress image (dimensions: {}x{}, format: {}, sampling: {}, quality: {}",
                img.getWidth(), img.getHeight(), pixelFmt, sampling, quality);
      throw new TurboJpegException(lib.tjGetErrorStr());
    }
    ByteBuffer outBuf = ByteBuffer.allocate(lenPtr.getValue().intValue()).order(runtime.byteOrder());
    bufPtr.get(0, outBuf.array(), 0, lenPtr.getValue().intValue());
    outBuf.rewind();
    return outBuf;
  } finally {
    if (codec != null && codec.address() != 0) lib.tjDestroy(codec);
    if (bufPtr != null && bufPtr.address() != 0) lib.tjFree(bufPtr);
  }
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:48,代码来源:TurboJpeg.java


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