Java Code Examples for javax.imageio.ImageWriter#getDefaultWriteParam()

The following examples show how to use javax.imageio.ImageWriter#getDefaultWriteParam() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JpegPageFileWriter.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@Override
public void saveToFile(TexturePacker.Settings settings, BufferedImage image, File file) throws IOException {
    ImageOutputStream ios = null;
    try {
        BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
        newImage.getGraphics().drawImage(image, 0, 0, null);
        image = newImage;

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
        ImageWriter writer = writers.next();
        ImageWriteParam param = writer.getDefaultWriteParam();
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(quality);
        ios = ImageIO.createImageOutputStream(file);
        writer.setOutput(ios);
        writer.write(null, new IIOImage(image, null, null), param);
    } finally {
        if (ios != null) {
            try { ios.close(); } catch (Exception ignored) { }
        }
    }
}
 
Example 2
Source File: ShortHistogramTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected File writeImageWithHist(BufferedImage bi) throws IOException {
    File f = File.createTempFile("hist_", ".png", new File("."));

    ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();

    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);

    ImageWriteParam param = writer.getDefaultWriteParam();
    ImageTypeSpecifier type = new ImageTypeSpecifier(bi);

    IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);

    /* add hIST node to image metadata */
    imgMetadata = upgradeMetadata(imgMetadata, bi);

    IIOImage iio_img = new IIOImage(bi,
                                    null, // no thumbnails
                                    imgMetadata);

    writer.write(iio_img);
    ios.flush();
    ios.close();
    return f;
}
 
Example 3
Source File: SunJPEGEncoderAdapter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encodes an image in JPEG format and writes it to an output stream.
 *
 * @param bufferedImage  the image to be encoded (<code>null</code> not 
 *     permitted).
 * @param outputStream  the OutputStream to write the encoded image to 
 *     (<code>null</code> not permitted).
 * 
 * @throws IOException if there is an I/O problem.
 * @throws NullPointerException if <code>bufferedImage</code> is 
 *     <code>null</code>.
 */
public void encode(BufferedImage bufferedImage, OutputStream outputStream) 
        throws IOException {
    if (bufferedImage == null) {
        throw new IllegalArgumentException("Null 'image' argument.");
    }
    if (outputStream == null) {
        throw new IllegalArgumentException("Null 'outputStream' argument.");
    }
    Iterator iterator = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = (ImageWriter) iterator.next();
    ImageWriteParam p = writer.getDefaultWriteParam();
    p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    p.setCompressionQuality(this.quality);
    ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
    writer.setOutput(ios);
    writer.write(null, new IIOImage(bufferedImage, null, null), p);
    ios.flush();
    writer.dispose();
    ios.close();
}
 
Example 4
Source File: Img.java    From java-tool with Apache License 2.0 6 votes vote down vote up
public void writeTo(OutputStream os, String mimeType) {
    ImageWriter writer = ImageIO.getImageWritersByMIMEType(mimeType(mimeType)).next();
    dropAlphaChannelIfJPEG(writer);
    ImageWriteParam params = writer.getDefaultWriteParam();

    if (!Float.isNaN(compressionQuality) && params.canWriteCompressed()) {
        params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        params.setCompressionType(params.getCompressionTypes()[0]);
        params.setCompressionQuality(compressionQuality);
    }

    ImageOutputStream ios = os(os);
    writer.setOutput(ios);
    IIOImage image = new IIOImage(get(), null, null);
    try {
        writer.write(null, image, params);
    } catch (IOException e) {
        throw ioException(e);
    }
    IO.flush(ios);
    writer.dispose();
}
 
Example 5
Source File: LUTCompareTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Image createTestImage() throws IOException  {
    BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 });
    BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 });

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif"));
    ImageWriteParam param = writer.getDefaultWriteParam();
    writer.setOutput(ios);
    writer.prepareWriteSequence(null);
    writer.writeToSequence(new IIOImage(frame1, null, null), param);
    writer.writeToSequence(new IIOImage(frame2, null, null), param);
    writer.endWriteSequence();
    writer.reset();
    writer.dispose();

    ios.flush();
    ios.close();

    return Toolkit.getDefaultToolkit().createImage("lut_test.gif");
}
 
Example 6
Source File: LUTCompareTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Image createTestImage() throws IOException  {
    BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 });
    BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 });

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif"));
    ImageWriteParam param = writer.getDefaultWriteParam();
    writer.setOutput(ios);
    writer.prepareWriteSequence(null);
    writer.writeToSequence(new IIOImage(frame1, null, null), param);
    writer.writeToSequence(new IIOImage(frame2, null, null), param);
    writer.endWriteSequence();
    writer.reset();
    writer.dispose();

    ios.flush();
    ios.close();

    return Toolkit.getDefaultToolkit().createImage("lut_test.gif");
}
 
Example 7
Source File: TopDownTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void writeWithCompression(BufferedImage src,
                                         String compression) throws IOException
{
    System.out.println("Compression: " + compression);
    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    if (writer == null) {
        throw new RuntimeException("Test failed: no bmp writer available");
    }
    File fout = File.createTempFile(compression + "_", ".bmp",
                                    new File("."));

    ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
    writer.setOutput(ios);

    BMPImageWriteParam param = (BMPImageWriteParam)
            writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compression);
    param.setTopDown(true);
    writer.write(null, new IIOImage(src, null, null), param);
    writer.dispose();
    ios.flush();
    ios.close();

    BufferedImage dst = ImageIO.read(fout);

    verify(dst);
}
 
Example 8
Source File: LegendManager.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Save image.
 *
 * @param image the grid image
 * @param formatName the format name
 * @param destinationFile the output
 * @param dpi the dpi
 * @return true, if successful
 * @throws IOException Signals that an I/O exception has occurred.
 */
private boolean saveGridImage(
        BufferedImage image, String formatName, File destinationFile, int dpi)
        throws IOException {
    if (!Files.delete(destinationFile)) {
        ConsoleManager.getInstance()
                .information(
                        this,
                        String.format(
                                "Failed to delete '%s'", destinationFile.getAbsolutePath()));
    }

    boolean finish = false;

    for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName);
            iw.hasNext() && !finish; ) {
        ImageWriter writer = iw.next();
        ImageWriteParam writeParam = writer.getDefaultWriteParam();
        ImageTypeSpecifier typeSpecifier =
                ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
        IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
        if (!(metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported())) {

            setDPI(metadata, dpi);

            final ImageOutputStream stream = ImageIO.createImageOutputStream(destinationFile);
            try {
                writer.setOutput(stream);
                writer.write(metadata, new IIOImage(image, null, metadata), writeParam);
            } finally {
                stream.close();
            }
            finish = true;
        }
    }

    return true;
}
 
Example 9
Source File: TopDownTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void writeWithCompression(BufferedImage src,
                                         String compression) throws IOException
{
    System.out.println("Compression: " + compression);
    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    if (writer == null) {
        throw new RuntimeException("Test failed: no bmp writer available");
    }
    File fout = File.createTempFile(compression + "_", ".bmp",
                                    new File("."));

    ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
    writer.setOutput(ios);

    BMPImageWriteParam param = (BMPImageWriteParam)
            writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compression);
    param.setTopDown(true);
    writer.write(null, new IIOImage(src, null, null), param);
    writer.dispose();
    ios.flush();
    ios.close();

    BufferedImage dst = ImageIO.read(fout);

    verify(dst);
}
 
Example 10
Source File: TopDownTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void writeWithCompression(BufferedImage src,
                                         String compression) throws IOException
{
    System.out.println("Compression: " + compression);
    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    if (writer == null) {
        throw new RuntimeException("Test failed: no bmp writer available");
    }
    File fout = File.createTempFile(compression + "_", ".bmp",
                                    new File("."));

    ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
    writer.setOutput(ios);

    BMPImageWriteParam param = (BMPImageWriteParam)
            writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compression);
    param.setTopDown(true);
    writer.write(null, new IIOImage(src, null, null), param);
    writer.dispose();
    ios.flush();
    ios.close();

    BufferedImage dst = ImageIO.read(fout);

    verify(dst);
}
 
Example 11
Source File: ImageListener.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 画像をjpeg形式で再圧縮します。
 *
 * @param in InputStream
 * @return InputStream
 */
private InputStream compressImage(InputStream in) {
    try {
        BufferedImage image = ImageIO.read(in);

        int width = image.getWidth();
        int height = image.getHeight();

        BufferedImage canvas = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        Graphics gc = canvas.createGraphics();
        gc.setColor(Color.WHITE);
        gc.fillRect(0, 0, width, height);
        gc.drawImage(image, 0, 0, null);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (ImageOutputStream ios = ImageIO.createImageOutputStream(out)) {
            ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
            try {

                ImageWriteParam iwp = writer.getDefaultWriteParam();
                if (iwp.canWriteCompressed()) {
                    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                    iwp.setCompressionQuality(0.8f);
                }
                writer.setOutput(ios);
                writer.write(null, new IIOImage(canvas, null, null), iwp);
            } finally {
                writer.dispose();
            }
        }
        return new ByteArrayInputStream(out.toByteArray());
    } catch (Exception e) {
        return null;
    }
}
 
Example 12
Source File: TopDownTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void writeWithCompression(BufferedImage src,
                                         String compression) throws IOException
{
    System.out.println("Compression: " + compression);
    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    if (writer == null) {
        throw new RuntimeException("Test failed: no bmp writer available");
    }
    File fout = File.createTempFile(compression + "_", ".bmp",
                                    new File("."));

    ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
    writer.setOutput(ios);

    BMPImageWriteParam param = (BMPImageWriteParam)
            writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compression);
    param.setTopDown(true);
    writer.write(null, new IIOImage(src, null, null), param);
    writer.dispose();
    ios.flush();
    ios.close();

    BufferedImage dst = ImageIO.read(fout);

    verify(dst);
}
 
Example 13
Source File: ReaderListenersTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(String compression) {
    try {
        BufferedImage img = createTestImage();

        ImageWriter iw = (ImageWriter)
            ImageIO.getImageWritersByFormatName("bmp").next();
        if (iw == null) {
            throw new RuntimeException("No writers for bmp format."
                                       + " Test failed.");
        }


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        iw.setOutput(ImageIO.createImageOutputStream(baos));
        ImageWriteParam param = iw.getDefaultWriteParam();
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionType(compression);

        iw.write(null, new IIOImage(img, null, null), param);
        baos.close();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        ImageReader ir = (ImageReader)
            ImageIO.getImageReadersByFormatName("bmp").next();
        if (ir == null) {
            throw new RuntimeException("No readers for bmp format."
                                       + " Test failed.");
        }

        IIOReadUpdateAdapter updateAdapter = new IIOReadUpdateAdapter();
        IIOReadProgressAdapter progressAdapter = new IIOReadProgressAdapter();
        ir.addIIOReadProgressListener(progressAdapter);
        ir.addIIOReadUpdateListener(updateAdapter);
        ir.setInput(ImageIO.createImageInputStream(bais));
        BufferedImage dst = ir.read(0);

        progressAdapter.checkResults();

        if (!updateAdapter.isImageUpdateUsed) {
            throw new RuntimeException("imageUpdate was not used."
                                       + " Test failed.");
        }
    } catch(IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Test failed");
    }
}
 
Example 14
Source File: BMPSubsamplingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private ImageWriteParam getImageWriteParam(ImageWriter writer, String value) {
    ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
    imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    imageWriteParam.setCompressionType(value);
    return imageWriteParam;
}
 
Example 15
Source File: BMPSubsamplingTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private ImageWriteParam getImageWriteParam(ImageWriter writer, String value) {
    ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
    imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    imageWriteParam.setCompressionType(value);
    return imageWriteParam;
}
 
Example 16
Source File: JavaxImageIOWriter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void after( ) throws ChartException
{
	super.after( );

	if ( _oOutputIdentifier != null )
	{

		// SEARCH FOR WRITER USING FORMAT
		ImageWriter iw = ImageWriterFactory.instance( )
				.createImageWriter( getFormat( ), outputFormat );

		// SEARCH FOR WRITER USING MIME TYPE
		if ( iw == null )
		{
			String s = getMimeType( );

			if ( s == null )
			{
				throw new ChartException( ChartDeviceExtensionPlugin.ID,
						ChartException.RENDERING,
						"JavaxImageIOWriter.exception.no.imagewriter.mimetype.and.format",//$NON-NLS-1$
						new Object[]{
								getMimeType( ),
								getFormat( ),
								getClass( ).getName( )
						},
						Messages.getResourceBundle( getULocale( ) ) );
			}
			Iterator<ImageWriter> it = ImageIO.getImageWritersByMIMEType( s );
			if ( !it.hasNext( ) )
			{
				throw new ChartException( ChartDeviceExtensionPlugin.ID,
						ChartException.RENDERING,
						"JavaxImageIOWriter.exception.no.imagewriter.mimetype", //$NON-NLS-1$
						new Object[]{
							getMimeType( )
						},
						Messages.getResourceBundle( getULocale( ) ) );
			}

			iw = it.next( );
		}

		logger.log( ILogger.INFORMATION,
				Messages.getString( "JavaxImageIOWriter.info.using.imagewriter", getULocale( ) ) //$NON-NLS-1$
						+ getFormat( )
						+ iw.getClass( ).getName( ) );

		// WRITE TO SPECIFIC FILE FORMAT
		final Object o = ( _oOutputIdentifier instanceof String ) ? new File( (String) _oOutputIdentifier )
				: _oOutputIdentifier;
		try
		{
			final ImageOutputStream ios = SecurityUtil.newImageOutputStream( o );
			ImageWriteParam iwp = iw.getDefaultWriteParam( );
			updateWriterParameters( iwp );
			iw.setOutput( ios );
			iw.write( (IIOMetadata) null,
					new IIOImage( (BufferedImage) _img, null, null ),
					iwp );
			ios.close( );
		}
		catch ( Exception ex )
		{
			throw new ChartException( ChartDeviceExtensionPlugin.ID,
					ChartException.RENDERING,
					ex );
		}
		finally
		{
			iw.dispose( );
		}
	}

	// FLUSH AND RESTORE STATE OF INTERNALLY CREATED IMAGE
	if ( !_bImageExternallySpecified )
	{
		_img.flush( );
		_img = null;
	}

	// ALWAYS DISPOSE THE GRAPHICS CONTEXT THAT WAS CREATED FROM THE IMAGE
	_g2d.dispose( );
	_g2d = null;
}
 
Example 17
Source File: BMPSubsamplingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public BMPSubsamplingTest() throws IOException {
    ImageWriter writer =
        ImageIO.getImageWritersByFormatName(format).next();

    ImageWriteParam wparam = writer.getDefaultWriteParam();
    wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    String[] types = wparam.getCompressionTypes();
    for (int t = 0; t < img_types.length; t++) {
        int img_type = img_types[t];
        System.out.println("Test for " + getImageTypeName(img_type));
        BufferedImage image = getTestImage(img_type);

        ImageTypeSpecifier specifier = new ImageTypeSpecifier(image);

        if (!writer.getOriginatingProvider().canEncodeImage(specifier)) {
            System.out.println("Writer does not support encoding this buffered image type.");
            continue;
        }

        for(int i=0; i<types.length; i++) {
            if ("BI_JPEG".equals(types[i])) {
                // exclude BI_JPEG from automatic test
                // due to color diffusion effect on the borders.
                continue;
            }

            if (canEncodeImage(types[i], specifier, img_type)) {
                System.out.println("compression type: " + types[i] +
                    " Supported for " + getImageTypeName(img_type));
            } else {
                System.out.println("compression type: " + types[i] +
                    " NOT Supported for " + getImageTypeName(img_type));
                continue;
            }
            ImageWriteParam imageWriteParam = getImageWriteParam(writer, types[i]);

            imageWriteParam.setSourceSubsampling(srcXSubsampling,
                                                 srcYSubsampling,
                                                 0, 0);
            File outputFile = new File("subsampling_test_" +
                getImageTypeName(img_type) + "__" +
                types[i] + ".bmp");
            ImageOutputStream ios =
                ImageIO.createImageOutputStream(outputFile);
            writer.setOutput(ios);

            IIOImage iioImg = new IIOImage(image, null, null);

            writer.write(null, iioImg, imageWriteParam);

            ios.flush();
            ios.close();

            BufferedImage outputImage = ImageIO.read(outputFile);
            checkTestImage(outputImage);
        }
    }
}
 
Example 18
Source File: BMPSubsamplingTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private ImageWriteParam getImageWriteParam(ImageWriter writer, String value) {
    ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();
    imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    imageWriteParam.setCompressionType(value);
    return imageWriteParam;
}
 
Example 19
Source File: BMPSubsamplingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public BMPSubsamplingTest() throws IOException {
    ImageWriter writer =
        ImageIO.getImageWritersByFormatName(format).next();

    ImageWriteParam wparam = writer.getDefaultWriteParam();
    wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    String[] types = wparam.getCompressionTypes();
    for (int t = 0; t < img_types.length; t++) {
        int img_type = img_types[t];
        System.out.println("Test for " + getImageTypeName(img_type));
        BufferedImage image = getTestImage(img_type);

        ImageTypeSpecifier specifier = new ImageTypeSpecifier(image);

        if (!writer.getOriginatingProvider().canEncodeImage(specifier)) {
            System.out.println("Writer does not support encoding this buffered image type.");
            continue;
        }

        for(int i=0; i<types.length; i++) {
            if ("BI_JPEG".equals(types[i])) {
                // exclude BI_JPEG from automatic test
                // due to color diffusion effect on the borders.
                continue;
            }

            if (canEncodeImage(types[i], specifier, img_type)) {
                System.out.println("compression type: " + types[i] +
                    " Supported for " + getImageTypeName(img_type));
            } else {
                System.out.println("compression type: " + types[i] +
                    " NOT Supported for " + getImageTypeName(img_type));
                continue;
            }
            ImageWriteParam imageWriteParam = getImageWriteParam(writer, types[i]);

            imageWriteParam.setSourceSubsampling(srcXSubsampling,
                                                 srcYSubsampling,
                                                 0, 0);
            File outputFile = new File("subsampling_test_" +
                getImageTypeName(img_type) + "__" +
                types[i] + ".bmp");
            ImageOutputStream ios =
                ImageIO.createImageOutputStream(outputFile);
            writer.setOutput(ios);

            IIOImage iioImg = new IIOImage(image, null, null);

            writer.write(null, iioImg, imageWriteParam);

            ios.flush();
            ios.close();

            BufferedImage outputImage = ImageIO.read(outputFile);
            checkTestImage(outputImage);
        }
    }
}
 
Example 20
Source File: BmpDefaultImageMetadataTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public BmpDefaultImageMetadataTest(String format) {
    try {
        bimg = new BufferedImage(200, 200, bimg.TYPE_INT_RGB);
        Graphics gg = bimg.getGraphics();
        gg.setColor(Color.red);
        gg.fillRect(50, 50, 100, 100);

        Iterator it = ImageIO.getImageWritersByFormatName(format);
        if (it.hasNext()) {
            writer = (ImageWriter) it.next();
        }
        if (writer == null) {
            throw new RuntimeException("No writer available for the given format."
                                       + " Test failed.");
        }
        writeParam = writer.getDefaultWriteParam();

        System.out.println("Testing Image Metadata for "+format+"\n");
        imageData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(bimg), writeParam);
        if (imageData == null) {
            System.out.println("return value is null. No default image metadata is associated with "+format+" writer");
            throw new RuntimeException("Default image metadata is null."
                                       + " Test failed.");
        }
        int j = 0;
        String imageDataNames[] = null;
        if(imageData != null) {
            System.out.println("Is standard metadata format supported (Image) ? "+
                               imageData.isStandardMetadataFormatSupported() );
            imageDataNames = imageData.getMetadataFormatNames();
            System.out.println("\nAll supported Metadata Format Names\n");
            if(imageDataNames!=null){
                for(j=0; j<imageDataNames.length; j++)  {
                    System.out.println("FORMAT NAME: "+imageDataNames[j]);
                    if (imageDataNames[j].equals(imageData.getNativeMetadataFormatName())) {
                        System.out.println("This is a Native Metadata format\n");
                    } else {
                        System.out.println("\n");
                    }
                    System.out.println("");
                    System.out.println("IIOImageMetadata DOM tree for "+imageDataNames[j]);
                    System.out.println("");
                    Node imageNode = imageData.getAsTree(imageDataNames[j]);
                    displayMetadata(imageNode);
                    System.out.println("\n\n");
                }
            }
        }
    }catch(Exception e){
        e.printStackTrace();
        throw new RuntimeException("Exception was thrown."
                                   + " Test failed.");
    }
}