• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BMP compression in JAI

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to compress bmp image but that is not showing any result, doing with following code. is there something missing in this

is there any other way which help to compress the bmp image



import java.awt.image.BufferedImage;
import java.awt.image.renderable.ParameterBlock;
import java.io.IOException;
import java.io.RandomAccessFile;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import com.sun.media.jai.codec.BMPEncodeParam;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.SeekableOutputStream;

public class ExportImages
{
private ImageEncoder encoder = null;
public static void main(String args[])
{
new ExportImages(args);
}

// Load the source image.
private PlanarImage loadImage(String imageName)
{
ParameterBlock pb = (new ParameterBlock()).add(imageName);
PlanarImage src1 = JAI.create("fileload", pb);
if (src1 == null)
{
System.out.println("Error in loading image " + imageName);
System.exit(1);
}
return src1;
}

/**
* Create seek output stream for scaling
*
* @param outFile
* @return
*/
private SeekableOutputStream createSeekOutputStream(String outFile)
{
SeekableOutputStream out = null;
try
{
out = new SeekableOutputStream(new RandomAccessFile(outFile, "rws"));
}
catch (IOException e)
{
System.out.println("IOException.");
System.exit(1);
}
return out;
}

/**
*
* @param args
*/
public ExportImages(String args[])
{
String inFile = "C:/Test.bmp";
String outputFile = "C:/Modified_image.bmp";
SeekableOutputStream out2 = createSeekOutputStream(outputFile);
PlanarImage src = loadImage(inFile);
BufferedImage bi = src.getAsBufferedImage();
ParameterBlock pb = new ParameterBlock();
pb.addSource(bi);
pb.add(1.0F);
pb.add(1.0F);
PlanarImage image = JAI.create("scale", pb, null).getRendering();
BMPEncodeParam bmpParam = new BMPEncodeParam();
bmpParam.setVersion(BMPEncodeParam.VERSION_3);
// Doing compress
bmpParam.setCompressed(true);
encoder = ImageCodec.createImageEncoder("BMP", out2, bmpParam);
try
{
encoder.encode(image);
out2.close();
}
catch (IOException e)
{
System.out.println("IOException at encoding..");
System.exit(1);
}
}
}



ThnX
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

that is not showing any result


What does this mean? No file is being created? Is the image encoder actually being run? Are there any error messages? If so, post the stack trace.
 
prashant gour
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is no error and image is being created but image does not get compressed even i use method setCompressed(true).

is there any thoughts???
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAI does not support compressed BMPs: JAI tutorial, section 13.4.

The newer javax.imageio package supports compression for BMPs. Here's a relevant article.
[ February 16, 2007: Message edited by: Ulf Dittmer ]
 
prashant gour
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have gone through with given link and did try the given example in link but image does not get compressed, image is being created only with BI_RGB
Not with remaining option of compression type but size does not get decreased.


Did I make any mistake? Looking for your response.
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic