Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Image Processing Java

Have Programming Question? Ask it here!
 
 
 


Dilvin Riyo
Image Processing Java
0 Answer(s)      2 years and 11 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);
  }

 }

Advertisement
View Answers

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
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  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 - 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
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
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
Speech Processing - Java Beginners
Speech Processing  I want to implement Speech Processing in Java. How can I do It? Please Answer me
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 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
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
image compression - Java Beginners
image compression  image compression in java coding
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
java image compression - Java Beginners
java image compression  image compression in 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
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
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
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
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
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 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
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 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
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
Steps for the payment gateway processing?
Steps for the payment gateway processing?  Steps for the payment gateway processing
read an image in java
read an image in java  qns: how we can read an image tell me about its code
image sending - Java Beginners
image sending  how to send an image from one computer(client) to other computer
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
request processing in servlets
request processing in servlets  how request processing is done in servlets and jsp   Please visit the following links: JSP Tutorials Servlet Tutorials Here, you will find several examples of processing request
Processing Sequence of DispatcherServlet
In this section, you will get to know about the processing sequence of DispatcherServlet
image comparison - Java Beginners
image comparison  hi all, pls help me to compare 2 images(in pixel and pattern) using jsp...the image pixels are in a xml file...  Hi friend, Read for more information. http://www.roseindia.net/jsp
image embadding - Java Beginners
image embadding  sir how to put images in JFrame/JPanel  Hi... class DisplayImage extends JPanel{ private BufferedImage image; public DisplayImage() { try { image
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
The product of data processing is
The product of data processing is   The product of data processing is 1. Data 2. Information 3. Software 4. Computer 5. All of the above   Answer: 3. Software
Abort JSP processing
Abort JSP processing  Can I just abort processing a JSP?   Yes. You can put a return statement to abort JSP processing
image display - Java Beginners
image display  i need to display all the images from the folder and i dont want give the image path.dynamically it should display. please help  Hi friend, Code to help in solving the problem var
image display - Java Beginners
image display   Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть...*" %><html><head><title>Retrive Image with jsp<
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
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
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
text processing program
text processing program  how can i compare letter by letter? what i was trying to do is a program that can define what is root word,prefix and suffix. plz help
java image display - Java Beginners
java image display  How to display images in the folder dynamically with out using database using java and jsp  Hi friend, Code to help in solving the problem var galleryarray=new Array
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
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
Converting HTML to image - Java Beginners
Converting HTML to image   Is it possible to convert html to image with java code ?   Hi friend, Please give the problem in details...://www.roseindia.net/java/ Thanks
Advertisements
 

 

 

DMCA.com