2017-10-28 58 views
0

我想生成第一頁的縮略圖。試圖用下面的頁面生成,不能打印具有良好分辨率的圖像,應該在縮放時顯示具有良好分辨率的圖像。即使我們有選擇打印縮略圖的前幾列也沒有問題。請建議。Aspose:爲第一頁生成縮略圖

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; 

回答

1

質量應該沒問題,如果你使用一些矢量圖像文件格式。例如,您可能會嘗試將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。