我想为首页生成缩略图。尝试在下一页生成,无法打印高分辨率的图像,应该在缩放时显示高分辨率的图像。即使我们可以选择在前几列打印指甲,也可以。请提出建议。
Workbook book = new Workbook(new ByteArrayInputStream(documentData));
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the vertical and horizontal resolution
imgOptions.setVerticalResolution(200);
imgOptions.setHorizontalResolution(200);
// Set the image's format
imgOptions.setImageFormat(ImageFormat.getJpeg());
// One page per sheet is enabled
imgOptions.setOnePagePerSheet(true);
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);
// Render the image for the sheet
sr.toImage(0, "mythumb.jpg");
// Creating Thumbnail
java.awt.Image img = ImageIO.read(new File("mythumb.jpg")).getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH);
BufferedImage img1 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
img1.createGraphics().drawImage(
ImageIO.read(new File("mythumb.jpg")).getScaledInstance(100, 100, img.SCALE_SMOOTH), 0, 0, null);
return img1;
最佳答案
如果使用某些矢量图像文件格式,则质量应该很好。例如,您可以尝试将Emf用作工作表的输出图像格式类型。如果要渲染要在图像中渲染的特定范围(在工作表中),则应在渲染工作表之前尝试设置所需的可打印区域,请参阅可在代码段开头添加的示例代码行:
例如
样例代码:
........
// Access the first worksheet
Worksheet worksheet = book.getWorksheets().get(0);
// Set the print area with your desired range
worksheet.getPageSetup().setPrintArea("E8:H15");
// Set all margins as 0 to get remove unnecessary white space
worksheet.getPageSetup().setLeftMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);
..........
我在Aspose担任技术支持/开发人员。