我的任务是压缩图像,重新调整大小,最后将水印添加到该图像。我面临的问题是在将Watermark写入该图像时Eclipse会抛出“Java堆大小错误”中的错误
BufferedImage bufferedImage = new BufferedImage(
icon.getIconWidth(), icon.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
借助Stackoverflow.com的帮助,我通过在Eclipse VM中添加-Xmx1024m来增加Java虚拟内存来修复此问题。但是当我在浏览器中运行这个Applet时,我的任务还没有完成,即图像处理在水印写入区域进行。我已将Java控制面板中的Java虚拟内存大小更改为-Xmx1024m,但我仍面临同样的问题。
任何帮助或建议表示赞赏。在此先感谢。
我的代码工作量和我面临的问题如下。
public BufferedImage setWaterMark(File imageFile, String watermark, String fontName, int fontSize, float opaque,int offsetSize,int intAngle,int intChkbox) throws Exception {
ImageIcon icon = new ImageIcon(imageFile.getPath());
System.out.println("Reading Image at Water mark");
BufferedImage bufferedImage = new BufferedImage(
icon.getIconWidth(), icon.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
g2d.drawImage(icon.getImage(), 0, 0, null);
g2d.setFont(new Font(fontName, Font.BOLD, fontSize));
g2d.drawImage(icon.getImage(), 0, 0, null);
AlphaComposite alpha = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, opaque);
g2d.setComposite(alpha);
g2d.setColor(Color.white);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
答案 0 :(得分:2)
来自Applet Deployment Parameters:
<APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300">
<PARAM name="java_arguments" value="-Xmx128m">
</APPLET>
如果小程序由JNLP启动,也可以在Java Web Start文件中完成。
答案 1 :(得分:-1)
1. open your .java file that contains the main().
2. Right click -> Select "Run As"-> "Run Configuration".
3. In the resulting Screen, under "Java Application" see if there exist ur already executed entry.If not Right click on "Java
Application" to create one.
4. Select that entry
5. Select "Arguments" tab.
6. Under "VM Argumets" area, type `-Xmx1g`
7. click Apply followed by Run button.
尝试上述步骤,看看是否收到同样的错误。