ProgramWindowJava

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)

[Previous] Compile error??
[Next] Please look at my code

Google


Java

Please look at my code
Help With For Loop?
Array program help
get source code from a website
Online Game
Upload 20MB File
ObjectOutputStream writing error
JDBC problem: NullPointerException
Writing a database
Declaring an array help
CMP and database connection problem
Need help with methods
Need help with this Code, please.
Threads
My first program.
memory address?
executable java file
Bitwise comparison?
Can't figure out Static Error?
Help!! using recursion to search an array