本文整理汇总了Java中javax.imageio.IIOImage.getRenderedImage方法的典型用法代码示例。如果您正苦于以下问题:Java IIOImage.getRenderedImage方法的具体用法?Java IIOImage.getRenderedImage怎么用?Java IIOImage.getRenderedImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.IIOImage
的用法示例。
在下文中一共展示了IIOImage.getRenderedImage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import javax.imageio.IIOImage; //导入方法依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
RenderedImage img = image.getRenderedImage();
if (stream == null) {
throw new IOException("Set an output first!");
}
if (param == null) {
param = getDefaultWriteParam();
}
Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
if (param.getSourceRegion() != null) {
sourceRegion = sourceRegion.intersection(param.getSourceRegion());
}
Raster raster = img.getData(sourceRegion);
int quality = 85;
if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
quality = (int) (param.getCompressionQuality() * 100);
}
try {
stream.write(lib.encode(raster, quality).array());
} catch (TurboJpegException e) {
throw new IOException(e);
}
}
示例2: getScaledInstance
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* Convenience method that returns a scaled instance of the provided
* {@code IIOImage}.
*
* @param iioSource the original image to be scaled
* @param scale the desired scale
* @return a scaled version of the original {@code IIOImage}
*/
public static IIOImage getScaledInstance(IIOImage iioSource, float scale) {
if (!(iioSource.getRenderedImage() instanceof BufferedImage)) {
throw new IllegalArgumentException("RenderedImage in IIOImage must be BufferedImage");
}
if (Math.abs(scale - 1.0) < 0.001) {
return iioSource;
}
BufferedImage source = (BufferedImage) iioSource.getRenderedImage();
BufferedImage target = getScaledInstance(source, (int) (scale * source.getWidth()), (int) (scale * source.getHeight()));
return new IIOImage(target, null, null);
}
示例3: write
import javax.imageio.IIOImage; //导入方法依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
RenderedImage img = image.getRenderedImage();
if (param == null) {
param = getDefaultWriteParam();
}
Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
if (param.getSourceRegion() != null) {
sourceRegion = sourceRegion.intersection(param.getSourceRegion());
}
Raster raster = img.getData(sourceRegion);
opj_cparameters cparams = ((OpenJp2ImageWriteParam) param).toNativeParams(lib);
lib.encode(raster, this.wrapper, cparams);
}
示例4: write
import javax.imageio.IIOImage; //导入方法依赖的package包/类
@Override
public void write( IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param ) throws IOException {
if ( param == null ) {
param = getDefaultWriteParam();
}
WebPWriteParam writeParam = (WebPWriteParam) param;
ImageOutputStream output = ( ImageOutputStream ) getOutput();
RenderedImage ri = image.getRenderedImage();
byte[] encodedData = WebP.encode(writeParam, ri);
output.write( encodedData );
}
示例5: BMPFileHeader
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* Creates the header from an output stream, which is not closed.
*
* @param out - the image output stream
* @param im - the image
* @throws IOException if an I/O error occured.
*/
public BMPFileHeader(ImageOutputStream out, IIOImage im) throws IOException
{
RenderedImage img = im.getRenderedImage();
int w = img.getWidth();
int h = img.getHeight();
bfOffBits = SIZE + BITMAPINFOHEADER_SIZE;
bfSize = ((w * h) * 3) + ((4 - ((w * 3) % 4)) * h) + bfOffBits;
write(out);
}
示例6: write
import javax.imageio.IIOImage; //导入方法依赖的package包/类
public void write (IIOMetadata streamMetadata, IIOImage i, ImageWriteParam param)
throws IOException
{
RenderedImage image = i.getRenderedImage();
Raster ras = image.getData();
int width = ras.getWidth();
int height = ras.getHeight();
ColorModel model = image.getColorModel();
int[] pixels = CairoGraphics2D.findSimpleIntegerArray (image.getColorModel(), ras);
if (pixels == null)
{
BufferedImage img;
if(model != null && model.hasAlpha())
img = CairoSurface.getBufferedImage(width, height);
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int[] pix = new int[4];
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
img.setRGB(x, y, model.getRGB(ras.getPixel(x, y, pix)));
pixels = CairoGraphics2D.findSimpleIntegerArray (img.getColorModel(),
img.getRaster());
model = img.getColorModel();
}
Thread workerThread = new Thread(this, "GdkPixbufWriter");
workerThread.start();
processImageStarted(1);
synchronized(pixbufLock)
{
streamImage(pixels, this.ext, width, height, model.hasAlpha(),
this);
}
synchronized(data)
{
data.add(DATADONE);
data.notifyAll();
}
while (workerThread.isAlive())
{
try
{
workerThread.join();
}
catch (InterruptedException ioe)
{
// Ignored.
}
}
if (exception != null)
throw exception;
processImageComplete();
}
示例7: BMPInfoHeader
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* Creates the info header from an output stream, which is not closed.
*
* @param out - the image output stream
* @param im - the image
* @param param - the image write param.
* @throws IOException if an I/O error occured.
*/
public BMPInfoHeader(ImageOutputStream out, IIOImage im, ImageWriteParam param) throws IOException
{
RenderedImage img = im.getRenderedImage();
ColorModel cMod = img.getColorModel();
biSize = SIZE;
biWidth = img.getWidth();
biHeight = img.getHeight();
biPlanes = 1;
if (param != null && param.canWriteCompressed())
{
String compType = param.getCompressionType();
if (compType.equals("BI_RLE8"))
{
biCompression = BI_RLE8;
biBitCount = 8;
}
else if (compType.equals("BI_RLE4"))
{
biCompression = BI_RLE4;
biBitCount = 4;
}
else
{
biCompression = BI_RGB;
biBitCount = (short) cMod.getPixelSize();
}
}
else
{
biBitCount = (short) cMod.getPixelSize();
biCompression = BI_RGB;
}
biXPelsPerMeter = 0x0;
biYPelsPerMeter = 0x0;
biClrUsed = 0;
biClrImportant = 0;
biSizeImage = ((biWidth * biHeight) * 3)
+ ((4 - ((biWidth * 3) % 4)) * biHeight);
out.write(intToDWord(biSize));
out.write(intToDWord(biWidth));
out.write(intToDWord(biHeight));
out.write(intToWord(biPlanes));
out.write(intToWord(biBitCount));
out.write(intToDWord(biCompression));
out.write(intToDWord(biSizeImage));
out.write(intToDWord(biXPelsPerMeter));
out.write(intToDWord(biYPelsPerMeter));
out.write(intToDWord(biClrUsed));
out.write(intToDWord(biClrImportant));
}
示例8: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
byte rgb[] = new byte[3];
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
rgb[0] = (byte) (value & 0xFF);
rgb[1] = (byte) ((value >> 8) & 0xFF);
rgb[2] = (byte) ((value >> 16) & 0xFF);
o.write(rgb);
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例9: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
ByteBuffer buf = ByteBuffer.allocate(size);
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
buf.put((byte) (value & 0xFF));
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
buf.flip();
o.write(uncompress(infoHeader.biWidth, infoHeader.biHeight, buf));
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例10: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
byte rgb[] = new byte[2];
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
rgb[0] = (byte) (value & 0xFF);
rgb[1] = (byte) (value >> 8 & 0xFF);
o.write(rgb);
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例11: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
byte rgb[] = new byte[1];
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
rgb[0] = (byte) (value & 0xFF);
o.write(rgb);
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例12: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
byte rgb[] = new byte[1];
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
rgb[0] = (byte) (value & 0xFF);
o.write(rgb);
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例13: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or
* null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
ByteBuffer buf = ByteBuffer.allocate(size);
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
buf.put((byte) (value & 0xFF));
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
buf.flip();
o.write(uncompress(infoHeader.biWidth, infoHeader.biHeight, buf));
}
catch (Exception wb)
{
wb.printStackTrace();
}
}
示例14: encode
import javax.imageio.IIOImage; //导入方法依赖的package包/类
/**
* The image encoder.
*
* @param o - the image output stream
* @param streamMetadata - metadata associated with this stream, or null
* @param image - an IIOImage containing image data.
* @param param - image writing parameters, or null
* @exception IOException if a write error occurs
*/
public void encode(ImageOutputStream o, IIOMetadata streamMetadata,
IIOImage image, ImageWriteParam param) throws IOException
{
int size;
int value;
int j;
int rowCount;
int rowIndex;
int lastRowIndex;
int[] bitmap;
byte rgb[] = new byte[4];
size = (infoHeader.biWidth * infoHeader.biHeight) - 1;
rowCount = 1;
rowIndex = size - infoHeader.biWidth;
lastRowIndex = rowIndex;
try
{
bitmap = new int[infoHeader.biWidth * infoHeader.biHeight];
PixelGrabber pg = new PixelGrabber((BufferedImage) image.getRenderedImage(),
0, 0, infoHeader.biWidth,
infoHeader.biHeight, bitmap, 0,
infoHeader.biWidth);
pg.grabPixels();
for (j = 0; j < size; j++)
{
value = bitmap[rowIndex];
rgb[0] = (byte) (value & 0xFF);
rgb[1] = (byte) ((value >> 8) & 0xFF);
rgb[2] = (byte) ((value >> 16) & 0xFF);
rgb[3] = (byte) ((value >> 24) & 0xFF);
o.write(rgb);
if (rowCount == infoHeader.biWidth)
{
rowCount = 1;
rowIndex = lastRowIndex - infoHeader.biWidth;
lastRowIndex = rowIndex;
}
else
rowCount++;
rowIndex++;
}
}
catch (Exception wb)
{
wb.printStackTrace();
}
}