我用java的
javax.print
和
swt的打印机类打印分辨率为4200 * 2850的图片都会出现内存益处和颜色不对呢?
javax.print
和
swt的打印机类打印分辨率为4200 * 2850的图片都会出现内存益处和颜色不对呢?
解决方案 »
- swing类中表的问题
- 静态页面如何调用静态页面?有几种方法?
- 十进制的数在内存中存放的是二进制,可以直接把他读出来吗?java中有直接的方法吗?
- 请教:如何知道一个字符的ASC码
- 请问:程序最终包含5个文件,如何发布一个可执行文件呢?
- 打印打印打印打印打印打印打印VSjavajavajavajavajavajavajavajavajava我要崩溃了!兄弟近来安慰两句吧!(有分140)
- Easy question
- 为何在applet中连接不到sql server 2000啊
- String 截取
- 能不能把java文件打包成EXE文件?有没有什么工具?
- ArrayList<E> 后面的 E 是什么意思?
- jdk1.6下载及jdk1.6的新特征
下边是其中一点点代码.
// 印刷設定データを取得する
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
if (pageSettingData.getPaperDirection().equals("LANDSCAPE")) {
aset.add(OrientationRequested.LANDSCAPE);
// paper.setImageableArea(0,0,pageHeight,pageWidth);
} else if (pageSettingData.getPaperDirection().equals("PORTRAIT")) {
aset.add(OrientationRequested.PORTRAIT);
// paper.setImageableArea(0,0,pageWidth,pageHeight);
} aset.add(new Copies(1));
aset.add(new JobName("エリアの印刷", null));还需要计算纸张大小,
if (pageSettingData.getPaperDirection().equals("LANDSCAPE")) {
if (paperSize.equals("A3")) {
pageWidth = 420 / 25.4 * 72;
pageHeight = 297 / 25.4 * 72;
} else if (paperSize.equals("A4")) {
pageWidth = 297 / 25.4 * 72;
pageHeight = 210 / 25.4 * 72;
} else if (paperSize.equals("A5")) {
pageWidth = 210 / 25.4 * 72;
pageHeight = 148 / 25.4 * 72;
} else if (paperSize.equals("B2")) {
pageWidth = 707 / 25.4 * 72;
pageHeight = 500 / 25.4 * 72;
} else if (paperSize.equals("B3")) {
pageWidth = 500 / 25.4 * 72;
pageHeight = 353 / 25.4 * 72;
} else if (paperSize.equals("B4")) {
pageWidth = 353 / 25.4 * 72;
pageHeight = 250 / 25.4 * 72;
}
} else if (pageSettingData.getPaperDirection().equals("PORTRAIT")) {
if (paperSize.equals("A3")) {
pageHeight = 420 / 25.4 * 72;
pageWidth = 297 / 25.4 * 72;
} else if (paperSize.equals("A4")) {
pageHeight = 297 / 25.4 * 72;
pageWidth = 210 / 25.4 * 72;
} else if (paperSize.equals("A5")) {
pageHeight = 210 / 25.4 * 72;
pageWidth = 148 / 25.4 * 72;
} else if (paperSize.equals("B2")) {
pageHeight = 707 / 25.4 * 72;
pageWidth = 500 / 25.4 * 72;
} else if (paperSize.equals("B3")) {
pageHeight = 500 / 25.4 * 72;
pageWidth = 353 / 25.4 * 72;
} else if (paperSize.equals("B4")) {
pageHeight = 353 / 25.4 * 72;
pageWidth = 250 / 25.4 * 72;
}
}
代码很多,只能告诉你这些.
this.palette = palette;
this.photos = new LinkedList<Photo>();
this.photos.addAll(photos);
this.printerNameH = printerNameH;
this.printerNameL = printerNameL;
} protected abstract void finish(); @Override
public void run() {
try {
//this.printUseImage();
this.printUseHDC();
} catch (Exception e) {
e.printStackTrace();
} finally {
finish();
}
} private void printUsePrintService() {
this.initDPI(); for (Photo photo : photos) {
if (photo.getImage() == null || photo.getCount() == 0) {
continue;
}
if (photo.getType() == 0) {
photo.getImage().fixImage(6 * DPI_H.x, 4 * DPI_H.y);
this.printImage(photo.getImage().save(), printerNameH, photo.getCount());
} else {
this.printImage(photo.getImage().save(), printerNameL, photo.getCount());
}
}
} private void printUseImage() {
this.initDPI();
this.createTempImage(60, 40);
Printer printerH = findPrinter(printerNameH);
Printer printerL = findPrinter(printerNameL);
GC gcH = new GC(printerH);
GC gcL = new GC(printerL); gcH.setClipping(0, 0, DPI_H.x * 6, DPI_H.y * 4);
gcL.setClipping(0, 0, DPI_H.x * 6, DPI_H.y * 4); boolean flagH = false;
boolean flagL = false;
for (Photo photo : photos) {
if (photo.getImage() == null || photo.getCount() == 0) {
continue;
}
if (photo.getType() == 0) {
if (flagH == false) {
printerH.startJob("photo");
flagH = true;
photo.getImage().getImage(tempImageH);
this.printImage(tempImageH, printerH, gcH, photo.getCount());
}
} else {
if (flagL == false) {
printerL.startJob("photo");
flagL = true;
photo.getImage().getImage(tempImageL);
this.printImage(tempImageL, printerL, gcL, photo.getCount());
}
}
}
if (flagH) {
printerH.endJob();
}
if (flagL) {
printerL.endJob();
}
gcH.dispose();
gcL.dispose();
printerH.dispose();
printerL.dispose();
} private void printUseHDC() {
this.initDPI();
Printer printerH = findPrinter(printerNameH);
Printer printerL = findPrinter(printerNameL);
GC gcH = new GC(printerH);
GC gcL = new GC(printerL);
gcH.setClipping(0, 0, DPI_H.x * 3 + 1, DPI_H.y * 2 + 1);
gcL.setClipping(0, 0, DPI_H.x * 6 + 1, DPI_H.y * 4 + 1); boolean flagH = false;
boolean flagL = false;
for (Photo photo : photos) {
if (photo.getImage() == null || photo.getCount() == 0) {
continue;
}
if (photo.getType() == 0) {
if (flagH == false) {
printerH.startJob("photo");
flagH = true;
int width = 3 * DPI_H.x;
int height = 2 * DPI_H.y;
this.printImage(photo.getImage(), printerH, gcH, width, height, photo.getCount());
}
} else {
if (flagL == false) {
printerL.startJob("photo");
flagL = true;
int width = 6 * DPI_L.x;
int height = 4 * DPI_L.y;
this.printImage(photo.getImage(), printerL, gcL, width, height, photo.getCount());
}
}
}
if (flagH) {
printerH.endJob();
}
if (flagL) {
printerL.endJob();
}
gcH.dispose();
gcL.dispose();
printerH.dispose();
printerL.dispose();
} private void createTempImage(int width, int height) {
try {
tempImageH = new ImageData(width * DPI_H.x / 10, height * DPI_H.y / 10, 32, palette);
tempImageL = new ImageData(width * DPI_L.x / 10, height * DPI_L.y / 10, 32, palette);
System.out.println("h:" + tempImageH.width + "," + tempImageH.height);
System.out.println("l:" + tempImageL.width + "," + tempImageL.height);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
} private void initDPI() {
try {
Printer printerH = findPrinter(printerNameH);
Printer printerL = findPrinter(printerNameL);
DPI_H = printerH.getDPI();
DPI_L = printerL.getDPI();
printerH.dispose();
printerL.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
} private Printer findPrinter(String name) {
PrinterData[] datas = Printer.getPrinterList(); for (PrinterData data : datas) {
if (data.name.equalsIgnoreCase(name)) {
return new Printer(data);
}
}
return null;
} private void printImage(ImageData data, Printer printer, GC gc, int count) {
Image image = new Image(printer, data);
for (int i = 0; i < count; i++) {
printer.startPage();
gc.drawImage(image, 0, 0);
printer.endPage();
}
image.dispose();
} private void printImage(ImageData data, Printer printer, GC gc, int x, int y) {
Image image = new Image(printer, data);
gc.drawImage(image, x, y);
image.dispose();
} private void printImage(ThumbImage image, Printer printer, GC gc, int width, int height, int count) {
System.out.println("size:" + width + "," + height);
// for(int i = 0;i<count;i++){
// printer.startPage();
image.print(gc.handle, width, height, count);
// printer.endPage();
// }
} private void printImage(String filename, String printerName, int count) {
try {
PrintService service = findPrintService(printerName);
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
FileInputStream stream = new FileInputStream(filename);
Doc doc = new SimpleDoc(stream, flavor, null);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
for (int i = 0; i < count; i++) {
service.createPrintJob().print(doc, null);
}
} catch (Exception e) {
e.printStackTrace();
}
} private PrintService findPrintService(String printerName) {
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
AttributeSet attributes = new HashAttributeSet();
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
for (PrintService service : services) {
if (service.getName().equalsIgnoreCase(printerName)) {
return service;
}
}
return null;
}
}
private void printUsePrintService()
是使用打印API
private void printUseHDC()
是使用Win API的DC进行打印
private void printUseImage()
是使用SWT进行绘制是不是打印机的问题啊,我就只有一个打印机,打印机的DPI为720