/// <summary>
 /// Release the image and client objects.
 /// </summary>
 private void ReleaseObjects()
 {
     lock (_loadCompleteCallback)
     {
         if (_releaseImageObject && _image != null)
         {
             _image.Dispose();
             _image = null;
         }
         if (_imageFileStream != null)
         {
             _imageFileStream.Dispose();
             _imageFileStream = null;
         }
     }
 }
 /// <summary>
 /// Load the image from inline base64 encoded string data.
 /// </summary>
 /// <param name="src">the source that has the base64 encoded image</param>
 private void SetFromInlineData(string src)
 {
     _image = GetImageFromData(src);
     if (_image == null)
         _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Failed extract image from inline data");
     _releaseImageObject = true;
     ImageLoadComplete(false);
 }
 /// <summary>
 /// Load the image file on thread-pool thread and calling <see cref="ImageLoadComplete"/> after.<br/>
 /// Calling <see cref="ImageLoadComplete"/> on the main thread and not thread-pool.
 /// </summary>
 /// <param name="source">the file path to get the image from</param>
 private void LoadImageFromFile(string source)
 {
     try
     {
         var imageFileStream = File.Open(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         lock (_loadCompleteCallback)
         {
             _imageFileStream = imageFileStream;
             if (!_disposed)
                 _image = _htmlContainer.Adapter.ImageFromStream(_imageFileStream);
             _releaseImageObject = true;
         }
         ImageLoadComplete();
     }
     catch (Exception ex)
     {
         _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Failed to load image from disk: " + source, ex);
         ImageLoadComplete();
     }
 }
예제 #4
0
 /// <summary>
 /// Draws the specified Image at the specified location and with the specified size.
 /// </summary>
 /// <param name="image">Image to draw. </param>
 /// <param name="destRect">Rectangle structure that specifies the location and size of the drawn image. </param>
 public abstract void DrawImage(RImage image, RRect destRect);
        /// <summary>
        /// Set the image using callback from load image event, use the given data.
        /// </summary>
        /// <param name="path">the path to the image to load (file path or uri)</param>
        /// <param name="image">the image to load</param>
        /// <param name="imageRectangle">optional: limit to specific rectangle of the image and not all of it</param>
        private void OnHtmlImageLoadEventCallback(string path, object image, RRect imageRectangle)
        {
            if (!_disposed)
            {
                _imageRectangle = imageRectangle;

                if (image != null)
                {
                    _image = _htmlContainer.Adapter.ConvertImage(image);
                    ImageLoadComplete(_asyncCallback);
                }
                else if (!string.IsNullOrEmpty(path))
                {
                    SetImageFromPath(path);
                }
                else
                {
                    ImageLoadComplete(_asyncCallback);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// On image load process is complete with image or without update the image box.
        /// </summary>
        /// <param name="image">the image loaded or null if failed</param>
        /// <param name="rectangle">the source rectangle to draw in the image (empty - draw everything)</param>
        /// <param name="async">is the callback was called async to load image call</param>
        private void OnLoadImageComplete(RImage image, RRect rectangle, bool async)
        {
            _imageWord.Image = image;
            _imageWord.ImageRectangle = rectangle;
            _imageLoadingComplete = true;
            _wordsSizeMeasured = false;

            if (_imageLoadingComplete && image == null)
            {
                SetErrorBorder();
            }

            if (!HtmlContainer.AvoidImagesLateLoading || async)
            {
                var width = new CssLength(Width);
                var height = new CssLength(Height);
                var layout = (width.Number <= 0 || width.Unit != CssUnit.Pixels) || (height.Number <= 0 || height.Unit != CssUnit.Pixels);
                HtmlContainer.RequestRefresh(layout);
            }
        }
예제 #7
0
 /// <summary>
 /// Get TextureBrush object that uses the specified image and bounding rectangle.
 /// </summary>
 /// <param name="image">The Image object with which this TextureBrush object fills interiors.</param>
 /// <param name="dstRect">A Rectangle structure that represents the bounding rectangle for this TextureBrush object.</param>
 /// <param name="translateTransformLocation">The dimension by which to translate the transformation</param>
 public abstract RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation);
예제 #8
0
        /// <summary>
        /// On image load process is complete with image or without update the image box.
        /// </summary>
        /// <param name="image">the image loaded or null if failed</param>
        /// <param name="rectangle">the source rectangle to draw in the image (empty - draw everything)</param>
        /// <param name="async">is the callback was called async to load image call</param>
        private void OnLoadImageComplete(RImage image, RRect rectangle, bool async)
        {
            _imageWord.Image = image;
            _imageWord.ImageRectangle = rectangle;
            _imageLoadingComplete = true;
            _wordsSizeMeasured = false;

            if (_imageLoadingComplete && image == null)
            {
                SetErrorBorder();
            }

            if (async)
            {
                HtmlContainer.RequestRefresh(IsLayoutRequired());
            }
        }
예제 #9
0
 /// <summary>
 /// On image load process complete with image request refresh for it to be painted.
 /// </summary>
 /// <param name="image">the image loaded or null if failed</param>
 /// <param name="rectangle">the source rectangle to draw in the image (empty - draw everything)</param>
 /// <param name="async">is the callback was called async to load image call</param>
 private void OnImageLoadComplete(RImage image, RRect rectangle, bool async)
 {
     if (image != null && async)
         HtmlContainer.RequestRefresh(false);
 }
예제 #10
0
 /// <summary>
 /// Save the given image to file by showing save dialog to the client.
 /// </summary>
 /// <param name="image">the image to save</param>
 /// <param name="name">the name of the image for save dialog</param>
 /// <param name="extension">the extension of the image for save dialog</param>
 /// <param name="control">optional: the control to show the dialog on</param>
 protected virtual void SaveToFileInt(RImage image, string name, string extension, RControl control = null)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 /// <summary>
 /// Set the given image to clipboard.
 /// </summary>
 /// <param name="image"></param>
 protected virtual void SetToClipboardInt(RImage image)
 {
     throw new NotImplementedException();
 }
예제 #12
0
 /// <summary>
 /// Save the given image to file by showing save dialog to the client.<br/>
 /// Not relevant for platforms that don't render HTML on UI element.
 /// </summary>
 /// <param name="image">the image to save</param>
 /// <param name="name">the name of the image for save dialog</param>
 /// <param name="extension">the extension of the image for save dialog</param>
 /// <param name="control">optional: the control to show the dialog on</param>
 public void SaveToFile(RImage image, string name, string extension, RControl control = null)
 {
     SaveToFileInt(image, name, extension, control);
 }
예제 #13
0
 /// <summary>
 /// Set the given image to clipboard.<br/>
 /// Not relevant for platforms that don't render HTML on UI element.
 /// </summary>
 /// <param name="image">the image object to set to clipboard</param>
 public void SetToClipboard(RImage image)
 {
     SetToClipboardInt(image);
 }
예제 #14
0
 /// <summary>
 /// Get image to be used if HTML image load failed.
 /// </summary>
 public RImage GetLoadingFailedImage()
 {
     if (_errorImage == null)
     {
         var stream = typeof(HtmlRendererUtils).Assembly.GetManifestResourceStream("TheArtOfDev.HtmlRenderer.Core.Utils.ImageError.png");
         if (stream != null)
             _errorImage = ImageFromStream(stream);
     }
     return _errorImage;
 }