Help in Writing text on image using jmagick
Hi,
I have tried to write text on the image using Jmagick.The code i have done is below.It is copiling but while executing it shows the eroor message as
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9111de, pid=3160, tid=1360
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_08-b03 mixed mode, sharing)
# Problematic frame:
# C [ntdll.dll+0x111de]
#
# An error report file with more information is saved as hs_err_pid3160.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
[error occurred during error reporting, step 270, id 0xc0000005]
and the code is:
import java.io.*;
import java.awt.*;
import magick.*;
class InsertText
{
public static void main(String a[]) throws IOException,MagickException
{
ImageInfo info=new ImageInfo("tigerShereKhanOnLog1.jpg");
MagickImage image=new MagickImage(info);
DrawInfo aInfo = new DrawInfo(info);
aInfo.setFill(PixelPacket.queryColorDatabase("yellow"));
aInfo.setUnderColor(PixelPacket.queryColorDatabase("yellow"));
aInfo.setOpacity(0);
aInfo.setPointsize(36);
aInfo.setFont("Arial");
aInfo.setGeometry("+40+40");
aInfo.setText("JMagick Tutorial");
image.annotateImage(aInfo);
image.setFileName("text.jpg");
image.writeImage(info);
}}
Could anybody solve and tell me how to do that.Thanks in advance
> ...
> Could anybody solve and tell me how to do that.Thanks
> in advance
I think you have a better change in finding an answer to your question by searching the mail-list archives of JMagick (or posting on their mail-list):
http://www.yeo.id.au/mailman/listinfo/jmagick
Good luck.
Why not use J2SE?
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
public class WaterMark {
public static void main(String[] args) throws IOException {
URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot-small.jpg");
BufferedImage im = ImageIO.read(url);
String text = DateFormat.getDateInstance(DateFormat.SHORT).format(new Date());
Graphics2D g = im.createGraphics();
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setFont(new Font("Lucida Bright", Font.ITALIC, 60));
g.rotate(-Math.PI/4, im.getWidth()/2, im.getHeight()/2);
TextLayout tl = new TextLayout(text, g.getFont(), g.getFontRenderContext());
Rectangle2D bounds = tl.getBounds();
double x = (im.getWidth()-bounds.getWidth())/2 - bounds.getX();
double y = (im.getHeight()-bounds.getHeight())/2 - bounds.getY();
Shape outline = tl.getOutline(AffineTransform.getTranslateInstance(x+2, y+1));
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
g.setPaint(Color.WHITE);
g.draw(outline);
g.setPaint(new GradientPaint(0, 0, Color.WHITE, 30, 20, new Color(128,128,255), true));
tl.draw(g, (float)x, (float)y);
g.dispose();
display(im);
}
public static void display(BufferedImage image) {
JFrame f = new JFrame("WaterMark");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JLabel(new ImageIcon(image)));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
http://java.sun.com/docs/books/tutorial/2d/index.html
Thanks Mr.prometheuzz
The code i given is taken from the link u said.but now the problem is if i commented the two lines
//aInfo.setFill(PixelPacket.queryColorDatabase("yellow"));
//aInfo.setUnderColor(PixelPacket.queryColorDatabase("yellow"));
the error is not coming but the string appended is printed on the console and not on the image.other operations like resizing,cropping all working fine but the annotation is the problem.help me
Regards
Venkatesh.R
Thanks Mr.prometheuzz
The code i given is taken from the link u said.but now the problem is if i commented the two lines
//aInfo.setFill(PixelPacket.queryColorDatabase("yellow"));
//aInfo.setUnderColor(PixelPacket.queryColorDatabase("yellow"));
the error is not coming but the string appended is printed on the console and not on the image.other operations like resizing,cropping all working fine but the annotation is the problem.help me
Regards
Venkatesh.R
Thanks.Mr.DrLaszloJamf I have to use jmagick library.
My suggestion was to post a message on the mail list of JMagick (after you've searched their archive, of course!) of which I posted a link.
Hi,
I have used awt packages as suggested by Mr.DrLaszloJamf only for text insertion on image.For all other cropping ,resizing iam using jmagick.It is working fine.But the problem is finally showing one alert message.Iam getting the exact output but the error message should not come.I dont know how to overcome the error.The error iam getting is
////////////////////////////////////////////////////////////
javaw.exe-Application Error
The instruction at "0x7c910f29" referenced memeory at "0x00000000".The memory could not be
"read".
Click OK to trminate the program
//////////////////////////////////////////////////////////////
above error is coming as alert box.
Very thanks to Mr prometheuzz
and Mr.DrLaszloJamf
Could anybody help me
Regards
Venkatesh.R