Home Answers Viewqa Java-Beginners Image Processing Java

 
 


Dilvin Riyo
Image Processing Java
0 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

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









Related Pages:
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 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
Compute the image processing - Java Beginners
Compute the image processing  Hi, Question 1: I have some... code here to find the averaging of the image (grey image) also, How do i compute... the subtraction of the image using hte g(x,y) = |f1(x,y) - f2(x,y) How do i change
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  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 - Java3D
image processing  hii i have to compare 2 images. for this i try to convert image into greyscale. i think the greyscale comparisonn is more effective than that of colour. pls give me the processing details.  Hi friend
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
how to make use of jerry's java image processing filter in java application?is there anyway to do this?
how to make use of jerry's java image processing filter in java application?is there anyway to do this?   how to make use of jerry's java image processing filter in java application?is there anyway to do
Audio Processing
Audio Processing  Sir, I want implement an audio recognition system by using java.. Is it possible? and tell me the process... thank you
Speech Processing - Java Beginners
Speech Processing  I want to implement Speech Processing in Java. How can I do It? Please Answer me
Error processing
Java: Error processing Error in user input or action If the user makes an error in input, give the appropriate feedback, and allow them to correct... in processing" as the error message. There was no hint as to whether is was my error
JavaScript array processing
JavaScript array processing       By processing array we simply mean that processing.... In this example of processing JavaScript array we have three array objects emp1, emp2
JDBC Batch Processing
JDBC Batch Processing In this section we are discussing about JDBC Batch processing. You will learn how to write Java programs for JDBC batch processing. The JDBC Batch processing is the mechanism where a group of related SQL statements
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
Processing stored procedure in MySQL - SQL
Processing stored procedure in MySQL  Dear All java with mysql developer..... i need to convert my SQL procedure to MySQL database... here is my Stored procedure in SQL.... create or replace procedure INVNAMES (bno
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
Form processing using Bean
Form processing using Bean In this section, we will create a JSP form using bean ,which will use a class file for processing. The standard way of handling forms in JSP is to define a "bean".  This is not a full Java
JDBC Batch Processing Example
JDBC Batch Processing Example: Batch processing mechanism provides a way... with a call to the database. By using batch processing you can reduce the extra..., you can learn about Batch processing and these few methods. The addBatch
Insert a Processing Instruction and a Comment Node
a Processing Node and Comment Node in a DOM document. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. Here the Document... Insert a Processing Instruction and a Comment Node  
Get the color values as a matrix of color image
Get the color values as a matrix of color image  I am new to java and image processing, i want to get the color values as a matrix from the color image for giving input to the compression algorithm by using java. plz provide
data processing is
data processing is   data processing is   Data processing is associated with commercial work. Data processing is also referred as Information System. Data processing is basically used for analyzing, processing
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
image compression - Java Beginners
image compression  image compression in java coding
Parallel Processing
; Introduction:   Threading concept is very important in Java Programming... application. Parallel Processing:   Parallel processing simultaneously... two or more processors. Parallel processing makes a program execution faster
java image compression - Java Beginners
java image compression  image compression in java
image in database
image in database  how to set image in database and retrieve it using servlet(java)in msaccess
Image_creation
Image_creation  how to create an image from a set of pixel values stored in array - in java
image scrambling
image scrambling  Hi frinds : i want to read image and scrambling it then saved using java any help please
scrolling image
scrolling image  How create a scrolling image in java
PDF to Image
PDF to Image  Java code to convert PDF to Image
Retrieving the Image from a database Table
Retrieving the Image from a database Table Consider a case where we want that along with the name of the person and its information, his image should also come. For this it is necessary that there must be his/her image in the database
image - Java Beginners
image  how to identify the watermarked image? or how to convert the watermarked image into original image? can you send that corresponding java code
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
Image in mysql
Image in mysql  Hi. How to insert and retrieve images in mysql db using JSP or JAVA Servlet? Thanks in advance
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
Java Parallel Processing Framework (JPPF) version 1.4 is now available
is done by the nodes. The open source JPPF (Java Parallel Processing Framaework) Community is based on java technology dealing in Grid Computing.... It applies the popular java idiom ?write once, deploy once, run everywhere
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path
image sending - Java Beginners
image sending  how to send an image from one computer(client) to other computer
read an image in java
read an image in java  qns: how we can read an image tell me about its code
Upload image
Upload image  Hai i beginner of Java ME i want code to capture QR Code image and send to the server and display value in Mobile Screen i want code in Java ME .java extension.. Regards senthil   To capture an image
read image
read image  java code to read an image in the form of an array.  ... ReadImageInArray { public static int[] getImagePixels(BufferedImage image...() * image.getHeight()]; try { grabber = new PixelGrabber(image, 0, 0
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
Inserting Image in a database Table
the method getWriter() of the class PrintWriter. To insert a image from our java... Inserting Image in MySql Database Table... that along with the name of the person and its information, his image should also
image insert - Java Beginners
image insert  i browsed the image by clicking d browse button.if i press submit button means d image automatically stored in db.then i have 2 retrieve d image separately...................... Untitled Document
image effects - Java Beginners
image effects  hey can u help me in loadin an image file... that will show you image crop effect: import java.sql.*; import java.awt.... java.awt.image.FilteredImageSource; public class Upload extends JPanel { BufferedImage image; Image img

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.