예제 #1
0
        /// <summary>Create an ImageData instance from the passed parameters.</summary>
        /// <param name="width">width of the image in pixels</param>
        /// <param name="height">height of the image in pixels</param>
        /// <param name="components">colour space components</param>
        /// <param name="bpc">bits per colour.</param>
        /// <param name="data">array containing raw image data</param>
        /// <param name="transparency">array containing transparency information</param>
        /// <returns>created ImageData object.</returns>
        public static ImageData Create(int width, int height, int components, int bpc, byte[] data, int[] transparency
                                       )
        {
            if (transparency != null && transparency.Length != components * 2)
            {
                throw new iText.IO.IOException(iText.IO.IOException.TransparencyLengthMustBeEqualTo2WithCcittImages);
            }
            if (components == 1 && bpc == 1)
            {
                byte[] g4 = CCITTG4Encoder.Compress(data, width, height);
                return(iText.IO.Image.ImageDataFactory.Create(width, height, false, RawImageData.CCITTG4, RawImageData.CCITT_BLACKIS1
                                                              , g4, transparency));
            }
            RawImageData image = new RawImageData(data, ImageType.RAW);

            image.height = height;
            image.width  = width;
            if (components != 1 && components != 3 && components != 4)
            {
                throw new iText.IO.IOException(iText.IO.IOException.ComponentsMustBe1_3Or4);
            }
            if (bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8)
            {
                throw new iText.IO.IOException(iText.IO.IOException.BitsPerComponentMustBe1_2_4or8);
            }
            image.colorSpace   = components;
            image.bpc          = bpc;
            image.data         = data;
            image.transparency = transparency;
            return(image);
        }
예제 #2
0
 protected internal static void UpdateRawImageParameters(RawImageData image, int width, int height, int components
                                                         , int bpc, byte[] data, int[] transparency)
 {
     if (transparency != null && transparency.Length != components * 2)
     {
         throw new iText.IO.IOException(iText.IO.IOException.TransparencyLengthMustBeEqualTo2WithCcittImages);
     }
     if (components == 1 && bpc == 1)
     {
         byte[] g4 = CCITTG4Encoder.Compress(data, width, height);
         UpdateRawImageParameters(image, width, height, false, RawImageData.CCITTG4, RawImageData.CCITT_BLACKIS1, g4
                                  , transparency);
     }
     else
     {
         UpdateRawImageParameters(image, width, height, components, bpc, data);
         image.SetTransparency(transparency);
     }
 }
예제 #3
0
 /** Gets an <CODE>Image</CODE> with the barcode.
  * @return the barcode <CODE>Image</CODE>
  * @throws BadElementException on error
  */
 virtual public Image GetImage()
 {
     byte[] b  = GetBitMatrix();
     byte[] g4 = CCITTG4Encoder.Compress(b, bm.GetWidth(), bm.GetHeight());
     return(Image.GetInstance(bm.GetWidth(), bm.GetHeight(), false, Image.CCITTG4, Image.CCITT_BLACKIS1, g4, null));
 }