Пример #1
0
        /// <summary>
        /// Creates a new <see cref="PdfImage"/> object from the specified uri with the specified format, optionally you can also specify a collection of effects to apply to the image.
        /// If the process of getting the image fails or the uri is wrong, <b>null</b> is returned.
        /// </summary>
        /// <param name="imageUri">Uri to image resource.</param>
        /// <param name="configuration">An image configuration to apply.</param>
        /// <param name="timeout">An image effects collection to apply.</param>
        /// <returns>
        /// A new <see cref="PdfImage"/> reference represents image.
        /// </returns>
        public static PdfImage FromUri(Uri imageUri, PdfImageConfig configuration = null, int timeout = 15000)
        {
            SentinelHelper.ArgumentNull(imageUri, nameof(imageUri));

            PdfImage result = PdfImage.Null;

            bool uriIsAccesible = imageUri.IsAccessible();

            if (!uriIsAccesible)
            {
                return(result);
            }

            try
            {
                PdfImage pdfimage;
                using (var response = GetResponse(imageUri, timeout))
                {
                    pdfimage = FromStream(response.GetResponseStream(), configuration);
                }

                if (pdfimage == PdfImage.Null)
                {
                    Thread.Sleep(300);
                    using (var response = GetResponse(imageUri, timeout))
                    {
                        pdfimage = FromStream(response.GetResponseStream(), configuration);
                    }

                    if (pdfimage == PdfImage.Null)
                    {
                        Thread.Sleep(500);
                        pdfimage = GetPdfImageByWebClient(imageUri);
                    }
                }

                result = pdfimage;
            }
            catch
            {
                return(result);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdfImage"/> class from image with optional image configuration.
        /// </summary>
        /// <param name="image">A reference to image object.</param>
        /// <param name="configuration">Image configuration reference.</param>
        internal PdfImage(NativeImage image, PdfImageConfig configuration = null)
        {
            var safeConfiguration = configuration;

            if (configuration == null)
            {
                safeConfiguration = PdfImageConfig.Default;
            }

            Path          = null;
            Configuration = safeConfiguration.Clone();
            OriginalImage = (NativeImage)image.Clone();

            var concreteOriginalImage = (Bitmap)image.Clone();

            if (Configuration.UseTransparentBackground)
            {
                if (Configuration.TransparentColor.Equals(PdfImageConfig.DefaultColor, StringComparison.OrdinalIgnoreCase))
                {
                    Configuration.SetParentImage(concreteOriginalImage);
                }

                concreteOriginalImage.MakeTransparent(Configuration.GetColor());
            }

            NativeImage processedImage = (NativeImage)concreteOriginalImage.Clone();

            if (Configuration.Effects != null)
            {
                processedImage = (NativeImage)concreteOriginalImage.ApplyEffects(Configuration.Effects).Clone();
            }

            ProcessedImage = (NativeImage)processedImage.Clone();
            ScaledHeight   = processedImage.Height;
            ScaledWidth    = processedImage.Width;

            Image = NativePdfImage.GetInstance(ProcessedImage, ImageFormat.Png);

            IsValid = true;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfImage"/> class with a image path and optional image configuration.
 /// </summary>
 /// <param name="imagePath">A reference to image path. The use of the <b>~</b> character is allowed to indicate relative paths, and you can also use <b>UNC</b> path.</param>
 /// <param name="configuration">Image configuration reference.</param>
 internal PdfImage(string imagePath, PdfImageConfig configuration = null) : this(NativeImage.FromFile(iTinIO.Path.PathResolver(imagePath)), configuration)
 {
     Path = iTinIO.File.ToUri(iTinIO.Path.PathResolver(imagePath));
 }
Пример #4
0
 /// <summary>
 /// Creates a new <see cref="PdfImage"/> object from specified stream, format and optional image effect collection.
 /// </summary>
 /// <param name="stream">Image as stream.</param>
 /// <param name="configuration">An image configuration to apply.</param>
 /// <returns>
 /// A new <see cref="PdfImage"/> reference represents image.
 /// </returns>
 public static PdfImage FromStream(Stream stream, PdfImageConfig configuration = null) => FromImage(NativeImage.FromStream(stream), configuration);
Пример #5
0
 /// <summary>
 /// Creates a new <see cref="PdfImage"/> object from specified image, format and optional image effect collection.
 /// </summary>
 /// <param name="image">Image reference.</param>
 /// <param name="configuration">An image configuration to apply.</param>
 /// <returns>
 /// A new <see cref="PdfImage"/> reference represents image.
 /// </returns>
 public static PdfImage FromImage(NativeImage image, PdfImageConfig configuration = null) => new PdfImage(image, configuration);
Пример #6
0
 /// <summary>
 /// Creates a new <see cref="PdfImage"/> object from specified image path and optional image configuration.
 /// </summary>
 /// <param name="imagePath">Image path. The use of the <b>~</b> character is allowed to indicate relative paths, and you can also use <b>UNC</b> path.</param>
 /// <param name="configuration">An image configuration to apply.</param>
 /// <returns>
 /// A new <see cref="PdfImage"/> reference represents image.
 /// </returns>
 public static PdfImage FromFile(string imagePath, PdfImageConfig configuration = null) => new PdfImage(imagePath, configuration);
Пример #7
0
 /// <summary>
 /// Creates a new <see cref="PdfImage"/> object from specified byte array, format and optional image effect collection.
 /// </summary>
 /// <param name="array">Image as byte array.</param>
 /// <param name="configuration">An image configuration to apply.</param>
 /// <returns>
 /// A new <see cref="PdfImage"/> reference represents image.
 /// </returns>
 public static PdfImage FromByteArray(byte[] array, PdfImageConfig configuration = null) => FromStream(array.ToMemoryStream(), configuration);