原創|其它|編輯:郝浩|2012-06-28 21:25:35.000|閱讀 868 次
概述:縮略圖是一個小的圖像,可以粘貼到Word文檔或PowerPoint演示文稿,為使用者提供工作表上內容的預覽。因此,生成工作表縮略圖是非常有用的。Aspose.Cells APIs 允許您將表輸出到圖像文件中,這樣就很容易生成縮略圖。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
縮略圖是一個小的圖像,可以粘貼到Word文檔或PowerPoint演示文稿,為使用者提供工作表上內容的預覽。因此,生成工作表縮略圖是非常有用的。Aspose.Cells APIs 允許您將表輸出到圖像文件中,這樣就很容易生成縮略圖。
[Java]
//........
import com.aspose.cells.*;
import java.io.*;
import java.awt.image.*;
import java.awt.*;
import javax.imageio.*;
public class Thumbnail1
{
public static void main(String[] args) throws Exception
{
//Instantiate and open an Excel file
Workbook book = new Workbook("e:\\test\\book1.xls");
//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
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, Image.SCALE_SMOOTH),0,0,null);
ImageIO.write(img1, "jpg", new File("thumbnail_out.jpg"));
}
}
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網