예제 #1
0
        /**
         * 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);
            }
        }
예제 #2
0
        /**
         * Extracts the image data from the Image. The data is formated for direct inclusion
         * in a rtf document
         *
         * @param image The Image for which to extract the content
         * @return The image data formated for the rtf document
         * @throws DocumentException If an error occurs accessing the image content
         */
        private byte[] GetImage(Image image)
        {
            MemoryStream imageTemp = new MemoryStream();

            try {
                Stream imageIn;
                if (imageType == Image.ORIGINAL_BMP)
                {
                    imageIn = new MemoryStream(MetaDo.WrapBMP(image));
                }
                else
                {
                    if (image.OriginalData == null)
                    {
                        imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream();
                    }
                    else
                    {
                        imageIn = new MemoryStream(image.OriginalData);
                    }
                    if (imageType == Image.ORIGINAL_WMF)   //remove the placeable header
                    {
                        Image.Skip(imageIn, 22);
                    }
                }
                int buffer = 0;
                int count  = 0;
                while ((buffer = imageIn.ReadByte()) != -1)
                {
                    String helperStr = buffer.ToString("X2");
                    byte[] t         = DocWriter.GetISOBytes(helperStr);
                    imageTemp.Write(t, 0, t.Length);
                    count++;
                    if (count == 64)
                    {
                        imageTemp.WriteByte((byte)'\n');
                        count = 0;
                    }
                }
            } catch (IOException ioe) {
                throw new DocumentException(ioe.ToString());
            }
            return(imageTemp.ToArray());
        }