-
How to defeat java.lang.OutOfMemoryError?
Hi there,
When I tried to run the below-mentioned code scenario, the JVM kicked me out with an error
"java.lang.OutOfMemoryError".
That's why, I give two VM parameters
-Xms256m -Xmx256m to increase Heap size.
It was working just only on superficial stage, the result
output image size is only 2.xxMB significantly differs from original one(original image is 7.xxMB). The image quality is not aggreesable.
How could I fix it?
----------------------------------
import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
import java.io.*;
import java.awt.image.BufferedImage;
import java.util.Iterator;
public class ImageReading {
public ImageReading() {
}
public static void main(String[] args) {
ImageReading imageReading1 = new ImageReading();
try{
File f = new File("D:\\space2.jpg");
BufferedImage bi = ImageIO.read(f);
File f1 = new File("D:\\space.jpg");
Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter)writers.next();
ImageOutputStream ios = ImageIO. createImageOutputStream(f1);
writer.setOutput(ios);
writer.write(bi);
} catch (Exception e ) {
e.printStackTrace();
}
}
}
---------------------------
dp_bhusaal
(A Java Developer)
Thanks,
dp_bhusaal
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks