Image Processing Java
Using This Code I Compressed A JPEG Image And the Original Size of the image is 257kb and The Compressed Image Size Is 27kb How Can I Decompress It Please Give Me The "SOURCE CODE" And Hee is my Source Code....
Please kindly Help Me?
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.JFrame;
import com.sun.media.jai.widget.DisplayJAI;
/*
* Shows how to save an image in JPEG with different compression factors.
* Based on code from http://forums.java.net/jive/thread.jspa?messageID=243429
* and from http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-compression-quality-when-saving-images-in-java
*/
public class DemoJPEGCompression
{
/*
* Application starting point, open an image and save it in JPEG with a
* compression factor.
*/
public static void main(String[] args) throws IOException
{
// Load the image (it is hard-coded here to make the code simpler).
String imageFile = "/tmp/folhas.png";
BufferedImage i = ImageIO.read(new File(imageFile));
showImage("Original Image", i);
// Show results with different compression ratio.
compressAndShow(i, 0.5f);
}
public static void compressAndShow(BufferedImage image, float quality) throws IOException
{
// Get a ImageWriter for jpeg format.
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpeg");
if (!writers.hasNext()) throw new IllegalStateException("No writers found");
ImageWriter writer = (ImageWriter) writers.next();
// Create the ImageWriteParam to compress the image.
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(quality);
// The output will be a ByteArrayOutputStream (in memory)
ByteArrayOutputStream bos = new ByteArrayOutputStream(32768);
ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
writer.setOutput(ios);
writer.write(null, new IIOImage(image, null, null), param);
ios.flush(); // otherwise the buffer size will be zero!
// From the ByteArrayOutputStream create a RenderedImage.
ByteArrayInputStream in = new ByteArrayInputStream(bos.toByteArray());
RenderedImage out = ImageIO.read(in);
int size = bos.toByteArray().length;
showImage("Compressed to " + quality + ": " + size + " bytes", out);
// Uncomment code below to save the compressed files.
// File file = new File("compressed."+quality+".jpeg");
// FileImageOutputStream output = new FileImageOutputStream(file);
// writer.setOutput(output); writer.write(null, new IIOImage(image, null,null), param);
}
/*
* This method just create a JFrame to display the image. Closing the window
* will close the whole application.
*/
private static void showImage(String title,RenderedImage image)
{
JFrame f = new JFrame(title);
f.getContentPane().add(new DisplayJAI(image));
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
View Answers
Ads
Related Tutorials/Questions & Answers:
Image Processing Java
Image Processing Java Using This Code I Compressed A JPEG
Image And the Original Size of the
image is 257kb and The Compressed
Image Size Is 27kb...://www.universalwebservices.net/web-programming-resources/
java/adjust-jpeg-
image-compression
image processing in java
image processing in java public class testing
{
static BufferedImage
image;
public static void main(String[] args) throws IOException...;Integer>();
image = ImageIO.read(new File("nn33.png"));
int w
Advertisements
image Processing
image Processing BCIF
Image Compresssion Algorithm s alossless
image Compression algorithm ,Pleas Help Me weather it can support only 24 bit bmp images
Image processing
Image processing i want a browsing program in
java in which we hv a small img and we hv to browse this img on a big
image so that we can find the similar type of
image in big img
image Processing
image Processing Please give Me a JPEG or GIf "LOSS LESS"
Image Compression and Decompression Source Code Please Help Me I don't want links Kindly help me Compression ratio not matter
Image Processing Tutorials in Java Programming Language
Tutorials and example of
processing the
image in the
Java Programming
Language
Java Programming Language is providing many APIs for
processing the
image...
image processing routine in the
Java Program. This is available with
JDK
jaav image processing
jaav
image processing hello there,
i am an engineering student..
i am going to do and project in whcih the software provides the user... to destination over an
image..
can you please guide me on how to start
Processing large file in Java
Processing Large Files in
Java with example code
Java programming language... support for file
processing.
Java API allows
you to create file, update file... for reading
and
processing large large text file using
Java code.
Java comes
Processing XML with Java
;
}
Processing XML with
Java
XML is cross-platform software, hardware... stand for "
Java API for XML Processing".
It is used for
processing...-based and read-write API on
Java
platform for
processing XML. It provides full
java rotate image
java rotate
image How to rotate
image to 90 and 180. can you please post an example to rotate
image
Java APIs for XML Processing (JAXP)
Java APIs for XML
Processing (JAXP)
JAXP (
Java APIs for XML
Processing) enables... kind of
processing instead it provides a mechanism to obtain parsed XML documents
Java APIs for XML Processing (JAXP)
Java APIs for XML
Processing (JAXP)
JAXP (
Java APIs for XML
Processing) enables... kind of
processing instead it provides a mechanism to obtain parsed XML documents
Image using Java coding
Image using
Java coding Hai,
Display
image in pdf file using
Java coding through Xsl file.. Please help me.. xsl file generate the pdf file
Java Image Browsing Applet
Java Image Browsing Applet Hi.
I want to create an applet which is embedded in html page which display
image by browsing the files in the computers hard disk...
Please help me out
image save to folder in java
image save to folder in java Hi,
I am working with
java. In my application i want to give facility to user to add and change
image. I use open dialog box to select
image, it will work properly i.e on button click open dialog
image upload in java
image upload in java Hi, I am working with
java. In my application i want to give facility to user to add and change
image. I use open dialog box to select
image, it will work properly i.e on button click open dialog is open
how to convert string to image in java
how to convert string to
image in java how to convert string to
image in
java? I know we need to convert
image to a byte array at some point in my application but do not know how to convert a
image into byte string. Please
Display Image in Java
Display
Image in
Java
This example takes an
image from the system and displays it on a frame
using ImageIO class. User enters the name of the
image using
image thinning or skeletonization program with java
image thinning or skeletonization program with java Dear Sir,
I want to thin my character
image with
java.
But I can't do. Please help me.
I mean I need Thinning or skeletonizatin program with
java.
Thanks in advance
Java image query from Rupesh
Java image query from Rupesh who give web page link to any submenu in menu bar of screen in
java so that after click on that submenu, this submenu direct link to web brower or web page
making use java image filters
making use
java image filters while making use any functions built in jerry's filter in
java application i get a NullPointerException.. I dont know the reason for this.. please give me a solution
Processing XML with Java
Processing XML using
Java
In this section we will see the API's available in
Java for
processing the
XML.
XML file is used on the internet to share... provides API's for
processing HTML
documents. In
Java there are many API's