當前位置: 首頁>>代碼示例>>Java>>正文


Java Image.ORIGINAL_BMP屬性代碼示例

本文整理匯總了Java中com.lowagie.text.Image.ORIGINAL_BMP屬性的典型用法代碼示例。如果您正苦於以下問題:Java Image.ORIGINAL_BMP屬性的具體用法?Java Image.ORIGINAL_BMP怎麽用?Java Image.ORIGINAL_BMP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.lowagie.text.Image的用法示例。


在下文中一共展示了Image.ORIGINAL_BMP屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: RtfImage

/**
 * Constructs a RtfImage for an Image.
 * 
 * @param doc The RtfDocument this RtfImage belongs to
 * @param image The Image that this RtfImage wraps
 * @throws DocumentException If an error occurred accessing the image content
 */
public RtfImage(RtfDocument doc, Image image) throws DocumentException
{
    super(doc);
    imageType = image.getOriginalType();
    if (!(imageType == Image.ORIGINAL_JPEG || imageType == Image.ORIGINAL_BMP
            || imageType == Image.ORIGINAL_PNG || imageType == Image.ORIGINAL_WMF || imageType == Image.ORIGINAL_GIF)) {
        throw new DocumentException("Only BMP, PNG, WMF, GIF and JPEG images are supported by the RTF Writer");
    }
    alignment = image.getAlignment();
    width = image.getWidth();
    height = image.getHeight();
    plainWidth = image.getPlainWidth();
    plainHeight = image.getPlainHeight();
    this.imageData = getImageData(image);
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:22,代碼來源:RtfImage.java

示例2: getImageData

/**
 * Extracts the image data from the Image.
 * 
 * @param image The image for which to extract the content
 * @return The raw image data, not formated
 * @throws DocumentException If an error occurs accessing the image content
 */
private byte[][] getImageData(Image image) throws DocumentException 
{
	final int WMF_PLACEABLE_HEADER_SIZE = 22;
    final RtfByteArrayBuffer bab = new RtfByteArrayBuffer();
    
    try {
        if(imageType == Image.ORIGINAL_BMP) {
        	bab.append(MetaDo.wrapBMP(image));
        } else {            	
        	final byte[] iod = image.getOriginalData();
        	if(iod == null) {
        		
            	final InputStream imageIn = image.getUrl().openStream();
                if(imageType == Image.ORIGINAL_WMF) { //remove the placeable header first
                	for(int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++) {
			if(imageIn.read() < 0) throw new EOFException("while removing wmf placeable header");
		}
                }
                bab.write(imageIn);
            	imageIn.close();
                
            } else {
            	
            	if(imageType == Image.ORIGINAL_WMF) {
            		//remove the placeable header                		
            		bab.write(iod, WMF_PLACEABLE_HEADER_SIZE, iod.length - WMF_PLACEABLE_HEADER_SIZE);
            	} else {
            		bab.append(iod);
            	}
            	
            }
        }
        
        return bab.toByteArrayArray();
        
    } catch(IOException ioe) {
        throw new DocumentException(ioe.getMessage());
    }
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:46,代碼來源:RtfImage.java

示例3: wrapBMP

public static byte[] wrapBMP(Image image) throws IOException {
        if (image.getOriginalType() != Image.ORIGINAL_BMP)
            throw new IOException("Only BMP can be wrapped in WMF.");
        InputStream imgIn;
        byte data[] = null;
        if (image.getOriginalData() == null) {
            imgIn = image.getUrl().openStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int b = 0;
            while ((b = imgIn.read()) != -1)
                out.write(b);
            imgIn.close();
            data = out.toByteArray();
        }
        else
            data = image.getOriginalData();
        int sizeBmpWords = (data.length - 14 + 1) >>> 1;
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        // write metafile header
        writeWord(os, 1);
        writeWord(os, 9);
        writeWord(os, 0x0300);
        writeDWord(os, 9 + 4 + 5 + 5 + (13 + sizeBmpWords) + 3); // total metafile size
        writeWord(os, 1);
        writeDWord(os, 14 + sizeBmpWords); // max record size
        writeWord(os, 0);
        // write records
        writeDWord(os, 4);
        writeWord(os, META_SETMAPMODE);
        writeWord(os, 8);

        writeDWord(os, 5);
        writeWord(os, META_SETWINDOWORG);
        writeWord(os, 0);
        writeWord(os, 0);

        writeDWord(os, 5);
        writeWord(os, META_SETWINDOWEXT);
        writeWord(os, (int)image.getHeight());
        writeWord(os, (int)image.getWidth());

        writeDWord(os, 13 + sizeBmpWords);
        writeWord(os, META_DIBSTRETCHBLT);
        writeDWord(os, 0x00cc0020);
        writeWord(os, (int)image.getHeight());
        writeWord(os, (int)image.getWidth());
        writeWord(os, 0);
        writeWord(os, 0);
        writeWord(os, (int)image.getHeight());
        writeWord(os, (int)image.getWidth());
        writeWord(os, 0);
        writeWord(os, 0);
        os.write(data, 14, data.length - 14);
        if ((data.length & 1) == 1)
            os.write(0);
//        writeDWord(os, 14 + sizeBmpWords);
//        writeWord(os, META_STRETCHDIB);
//        writeDWord(os, 0x00cc0020);
//        writeWord(os, 0);
//        writeWord(os, (int)image.height());
//        writeWord(os, (int)image.width());
//        writeWord(os, 0);
//        writeWord(os, 0);
//        writeWord(os, (int)image.height());
//        writeWord(os, (int)image.width());
//        writeWord(os, 0);
//        writeWord(os, 0);
//        os.write(data, 14, data.length - 14);
//        if ((data.length & 1) == 1)
//            os.write(0);

        writeDWord(os, 3);
        writeWord(os, 0);
        os.close();
        return os.toByteArray();
    }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:76,代碼來源:MetaDo.java


注:本文中的com.lowagie.text.Image.ORIGINAL_BMP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。