/// <summary> /// Creates a new <see cref="XlsxImage"/> 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="XlsxImage"/> reference represents image. /// </returns> public static XlsxImage FromUri(Uri imageUri, XlsxImageConfig configuration = null, int timeout = 15000) { SentinelHelper.ArgumentNull(imageUri, nameof(imageUri)); XlsxImage result = XlsxImage.Null; bool uriIsAccesible = imageUri.IsAccessible(); if (!uriIsAccesible) { return(result); } try { XlsxImage docximage; using (var response = GetResponse(imageUri, timeout)) { docximage = FromStream(response.GetResponseStream(), configuration); } if (docximage == XlsxImage.Null) { Thread.Sleep(300); using (var response = GetResponse(imageUri, timeout)) { docximage = FromStream(response.GetResponseStream(), configuration); } if (docximage == XlsxImage.Null) { Thread.Sleep(500); docximage = GetDocXImageByWebClient(imageUri); } } result = docximage; } catch { return(result); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="XlsxImage"/> class with a image path and optional image configuration. /// </summary> /// <param name="image">A reference to image object.</param> /// <param name="configuration">Image configuration reference.</param> internal XlsxImage(Image image, XlsxImageConfig configuration = null) { var safeConfiguration = configuration; if (configuration == null) { safeConfiguration = XlsxImageConfig.Default; } Path = null; Configuration = safeConfiguration.Clone(); OriginalImage = (Image)image.Clone(); var concreteOriginalImage = (Bitmap)image.Clone(); if (Configuration.UseTransparentBackground) { if (Configuration.TransparentColor.Equals(XlsxImageConfig.DefaultColor, StringComparison.OrdinalIgnoreCase)) { Configuration.SetParentImage(concreteOriginalImage); } concreteOriginalImage.MakeTransparent(Configuration.GetColor()); } Image processedImage = (Image)concreteOriginalImage.Clone(); if (Configuration.Effects != null) { processedImage = (Image)concreteOriginalImage.ApplyEffects(Configuration.Effects).Clone(); } ProcessedImage = (Image)processedImage.Clone(); ScaledHeight = processedImage.Height; ScaledWidth = processedImage.Width; Image = (Image)ProcessedImage.Clone(); IsValid = true; }
/// <summary> /// Initializes a new instance of the <see cref="XlsxImage"/> 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 XlsxImage(string imagePath, XlsxImageConfig configuration = null) : this(Image.FromFile(iTinIO.Path.PathResolver(imagePath)), configuration) { Path = iTinIO.File.ToUri(iTinIO.Path.PathResolver(imagePath)); }
/// <summary> /// Creates a new <see cref="XlsxImage"/> 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="XlsxImage"/> reference represents image. /// </returns> public static XlsxImage FromStream(Stream stream, XlsxImageConfig configuration = null) => FromImage(Image.FromStream(stream), configuration);
/// <summary> /// Creates a new <see cref="XlsxImage"/> object from specified image and optional image effect collection. /// </summary> /// <param name="image">Image reference.</param> /// <param name="configuration">An image effects collection to apply.</param> /// <returns> /// A new <see cref="XlsxImage"/> reference represents image. /// </returns> public static XlsxImage FromImage(Image image, XlsxImageConfig configuration = null) => new XlsxImage(image, configuration);
/// <summary> /// Creates a new <see cref="XlsxImage"/> 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="XlsxImage"/> reference represents image. /// </returns> public static XlsxImage FromFile(string imagePath, XlsxImageConfig configuration = null) => new XlsxImage(imagePath, configuration);
/// <summary> /// Creates a new <see cref="XlsxImage"/> 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="XlsxImage"/> reference represents image. /// </returns> public static XlsxImage FromByteArray(byte[] array, XlsxImageConfig configuration = null) => FromStream(array.ToMemoryStream(), configuration);