/// <summary> /// Extracts the image data from the Image. /// @throws DocumentException If an error occurs accessing the image content /// </summary> /// <param name="image">The image for which to extract the content</param> /// <returns>The raw image data, not formated</returns> private byte[][] getImageData(Image image) { int wmfPlaceableHeaderSize = 22; RtfByteArrayBuffer bab = new RtfByteArrayBuffer(); try { if (_imageType == Image.ORIGINAL_BMP) { bab.Append(MetaDo.WrapBmp(image)); } else { byte[] iod = image.OriginalData; if (iod == null) { Stream imageIn = image.Url.GetResponseStream(); if (_imageType == Image.ORIGINAL_WMF) { //remove the placeable header first for (int k = 0; k < wmfPlaceableHeaderSize; k++) { if (imageIn.ReadByte() < 0) { throw (new IOException("while removing wmf placeable header")); } } } bab.Write(imageIn); imageIn.Dispose(); } else { if (_imageType == Image.ORIGINAL_WMF) { //remove the placeable header bab.Write(iod, wmfPlaceableHeaderSize, iod.Length - wmfPlaceableHeaderSize); } else { bab.Append(iod); } } } return(bab.ToArrayArray()); } catch (IOException ioe) { throw new DocumentException(ioe.Message); } }
/** * 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) { int WMF_PLACEABLE_HEADER_SIZE = 22; RtfByteArrayBuffer bab = new RtfByteArrayBuffer(); try { if (imageType == Image.ORIGINAL_BMP) { bab.Append(MetaDo.WrapBMP(image)); } else { byte[] iod = image.OriginalData; if (iod == null) { Stream imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream(); if (imageType == Image.ORIGINAL_WMF) //remove the placeable header first { for (int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++) { if (imageIn.ReadByte() < 0) { throw (new IOException("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.ToArrayArray()); } catch (IOException ioe) { throw new DocumentException(ioe.Message); } }