0
回答
使用jmagick对图片进行文字水印处理的时候出现的问题
#
# An unexpected error has been detected by Java Runtime Environment:
#
# java.lang.OutOfMemoryError: requested 448 bytes for unsigned char in C:\BUILD_AREA\jdk6_10\hotspot\src\share\vm\code\codeBlob.cpp. Out of swap space?
#
#  Internal Error (allocation.inline.hpp:42), pid=4480, tid=4536
#  Error: unsigned char in C:\BUILD_AREA\jdk6_10\hotspot\src\share\vm\code\codeBlob.cpp
#
# Java VM: Java HotSpot(TM) Client VM (11.0-b15 mixed mode, sharing windows-x86)
# An error report file with more information is saved as:
# I:\JavaEclipse\s2s_Test\hs_err_pid4480.log
[thread 6016 also had an error]
javaw.exe: UnableToAcquireString `No such file or directory' @ string.c/AcquireString/126.
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#
这个是什么错误?我在用jmagick对图片进行文字水印的时候出错了!求解决,谢谢大虾们
源函数代码:
public static void initTextToImg(String filePath, String toImg,  String text) throws MagickException{
ImageInfo info = new ImageInfo(filePath);
if (filePath.toUpperCase().endsWith("JPG") || filePath.toUpperCase().endsWith("JPEG")) {
info.setCompression(CompressionType.JPEGCompression); //压缩类别为JPEG格式
info.setPreviewType(PreviewType.JPEGPreview); //预览格式为JPEG格式
info.setQuality(95);
}
MagickImage aImage = new MagickImage(info);
Dimension imageDim = aImage.getDimension();
int wideth = imageDim.width;
int height = imageDim.height;
if (wideth > 660) {
height = 660 * height / wideth;
wideth = 660;
}
int a = 0;
int b = 0;
String[] as = text.split("");
for (String string : as) {
if(string.matches("[\u4E00-\u9FA5]")){
a++;
}
if(string.matches("[a-zA-Z0-9]")){
b++;
}
}
int tl = a*12 + b*6 + 300;
MagickImage scaled = aImage.scaleImage(wideth, height);
if(wideth > tl && height > 5){
DrawInfo aInfo = new DrawInfo(info);
aInfo.setFill(PixelPacket.queryColorDatabase("white"));
aInfo.setUnderColor(new PixelPacket(0,0,0,100));
aInfo.setPointsize(12);
//解决中文乱码问题,自己可以去随意定义个自己喜欢字体,我在这用的微软雅黑
String fontPath = "C:/WINDOWS/Fonts/MSYH.TTF";
// String fontPath = "/usr/maindata/MSYH.TTF";
aInfo.setFont(fontPath);
aInfo.setTextAntialias(true);
aInfo.setOpacity(0);
aInfo.setText(" " + text + "于 " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 上传于XXXX网,版权归作者所有!");
aInfo.setGeometry("+" + (wideth-tl) + "+" + (height-5));
scaled.annotateImage(aInfo);
}
scaled.setFileName(toImg);
scaled.writeImage(info);
scaled.destroyImages();
}
举报
Jonee_Leo
发帖于6年前 0回/783阅
顶部