打印 .TIF 文件
我可以使用以下代码片段成功打印 .GIF、.JPG 或 .PNG,但它不适用于 .TIF 文件。即使添加 chromaticity.color 属性后,我也无法获取颜色。
public class PrintImage {
static public void main(String args[]) throws Exception {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
pras.add(chromaticity.color);
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
if (pss.length == 0)
throw new RuntimeException("No printer services available.");
PrintService ps = pss[0];
System.out.println("Printing to " + ps);
DocPrintJob job = ps.createPrintJob();
String fileName = "C:/labels/2.tif"
FileInputStream fin = new FileInputStream(fileName);
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
job.print(doc, pras);
fin.close();
}
如何支持 .TIF 打印?
I am able to print a .GIF, .JPG or .PNG successfully using the following code snippet but it doesn't work for .TIF file. Also I can't get the color even after adding the chromaticity.color
attribute.
public class PrintImage {
static public void main(String args[]) throws Exception {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
pras.add(chromaticity.color);
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
if (pss.length == 0)
throw new RuntimeException("No printer services available.");
PrintService ps = pss[0];
System.out.println("Printing to " + ps);
DocPrintJob job = ps.createPrintJob();
String fileName = "C:/labels/2.tif"
FileInputStream fin = new FileInputStream(fileName);
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
job.print(doc, pras);
fin.close();
}
How do I support .TIF for printing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 TIFF 使用 Java 高级成像 API。 JAI 可以处理多页 TIFF 文件、TIFF 中的 JPEG 和一些压缩方案。如果您在打印时仍然遇到问题,可以使用 API 将 TIFF 文件转换为 PNG。
Use Java Advanced Imaging API for TIFF. JAI can handle multipage TIFF files, JPEG in TIFF and a few compression schemes. If you still have trouble printing, with the API you could convert your TIFF file to PNG.