我需要在文件图像中插入文件名。我们使用RasterMaster Snow API来实现这一点。我知道我们可以使用注解合并在图像中插入文本。但是找不到任何关于如何使用Snow注解在图像中合并文本的帮助。下面是代码片段,但是不起作用。
它会无一例外地生成test1.tiff镜像,但不会在生成的镜像中插入文件名。看起来我没有正确使用snow注解合并功能。
try {
File source= new File("D:\\rastermaster\\test1.pdf");
File result = new File("D:\\rastermaster\\test1.tiff");
Snowbnd snowbnd = new Snowbnd();
Snow.SANN_RECT sn = new Snow.SANN_RECT();
sn.left=1200;
sn.right=1200;
sn.top=1200;
sn.bottom=1200;
Snow.SANN_POINT p1 = new Snow.SANN_POINT();
p1.x=12;
p1.y=12;
Snow.SANN_POINT p2 = new Snow.SANN_POINT();
p2.x=102;
p2.y=102;
Snow.SANN_POINT pn[] = new Snow.SANN_POINT[]{p1,p2};
int status = snowbnd.IMG_decompress_bitmap(source.getAbsolutePath(), 0);
// snowbnd.IMGLOW_set_bitmap_name("BT-7208_file_name", "BT-7208");
//snowbnd.IMGLOW_set_print_header("BT-7208_file_name", "BT-7208",1); snowbnd
snowbnd.IMGLOW_set_pdf_output((int) PD4Constants.A4.getWidth(), (int) PD4Constants.A4.getHeight());
SnowAnn sann = new SnowAnn(200, 300);
// Sann = new SnowAnn(Simage.getWidth(),Simage.getHeight());
//Set the size and position of the rectangle using
sann.SANN_set_croprect(120, 120, 120, 120);
//add text using
sann.SANN_add_object(3, sn, "file_name".getBytes(), pn, "file_name".length());
//sann.textString="hello";
//if you wish to view the annotation use
//sann.SANN_display_annotations(grp, f, status, status, status, status);
//burn the annotation into the file using
int status2 =sann.SANN_merge_annotations(snowbnd, null);
status = snowbnd.IMG_save_bitmap(result.getAbsolutePath(), 16);
if (status < 0) {
System.out.println("fail");
}
} catch (RuntimeException re) {
re.printStackTrace();
} catch (Error err) {
err.printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
} finally {
}我们如何才能做到这一点?
发布于 2015-10-06 13:32:58
我找到了解决方案。在下面的代码行中
sann.SANN_add_object(3, sn, "file_name".getBytes(), pn, "file_name".length());它需要传递13而不是3作为第一个参数。
sann.SANN_add_object(13, sn, "file_name".getBytes(), pn, "file_name".length());当我们给出值3时,它忽略了object的值(我们需要插入的文本)是作为参数传递给sann.SANN_add_object(......)的Snow.SANN_POINT[]数组的insert.Also值。数组可以为空(至少我不知道它的用途)。
File source= new File("D:\\demo\\test.pdf");
File result = new File("D:\\demo\\test.tif");
Snowbnd snowbnd = new Snowbnd();
snowbnd.IMGLOW_set_license_path("path of licence");
int status = snowbnd.IMG_decompress_bitmap(source.getAbsolutePath(), 0);
Snow.SANN_RECT sn = new Snow.SANN_RECT();
sn.left=0;
sn.right=600;
sn.top=0;
sn.bottom=20;
SnowAnn sann = new SnowAnn(snowbnd.getWidth(), snowbnd.getHeight());
sann.SANN_set_croprect(0, 0, 200, 600);
sann.ann_font_height=1;
sann.ann_bold=1;
sann.SANN_set_fcolor(0,0,0);
sann.SANN_add_object(13, sn, "file_name".getBytes(), null, "file_name".length());
int status2 =sann.SANN_merge_annotations(snowbnd, null);
status = snowbnd.IMG_save_bitmap(result.getAbsolutePath(), 16);https://stackoverflow.com/questions/32734929
复制相似问题