Пример #1
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;
 }
Пример #2
0
 /// <summary>
 /// Get image to be used while HTML image is loading.
 /// </summary>
 public RImage GetLoadingImage()
 {
     if (_loadImage == null)
     {
         var stream = typeof(HtmlRendererUtils).Assembly.GetManifestResourceStream("TheArtOfDev.HtmlRenderer.Core.Utils.ImageLoad.png");
         if (stream != null)
         {
             _loadImage = ImageFromStream(stream);
         }
     }
     return(_loadImage);
 }
Пример #3
0
 public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation)
 {
     var brush = new TextureBrush(((ImageAdapter)image).Image, Utils.Convert(dstRect));
     brush.TranslateTransform((float)translateTransformLocation.X, (float)translateTransformLocation.Y);
     return new BrushAdapter(brush, true);
 }
Пример #4
0
        /// <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);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Set the given image to clipboard.
 /// </summary>
 /// <param name="image"></param>
 protected virtual void SetToClipboardInt(RImage image)
 {
     throw new NotImplementedException();
 }
Пример #6
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);
 }
Пример #7
0
 /// <summary>
 /// Get image to be used while HTML image is loading.
 /// </summary>
 public RImage GetLoadingImage()
 {
     if (_loadImage == null)
     {
         var stream = typeof(HtmlRendererUtils).Assembly.GetManifestResourceStream("TheArtOfDev.HtmlRenderer.Core.Utils.ImageLoad.png");
         if (stream != null)
             _loadImage = ImageFromStream(stream);
     }
     return _loadImage;
 }
Пример #8
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);
Пример #9
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);
Пример #10
0
 protected override void SetToClipboardInt(RImage image)
 {
     Clipboard.SetImage(((ImageAdapter)image).Image);
 }
Пример #11
0
        protected override void SaveToFileInt(RImage image, string name, string extension, RControl control = null)
        {
            using (var saveDialog = new SaveFileDialog())
            {
                saveDialog.Filter = "Images|*.png;*.bmp;*.jpg";
                saveDialog.FileName = name;
                saveDialog.DefaultExt = extension;

                var dialogResult = control == null ? saveDialog.ShowDialog() : saveDialog.ShowDialog(((ControlAdapter)control).Control);
                if (dialogResult == DialogResult.OK)
                {
                    ((ImageAdapter)image).Image.Save(saveDialog.FileName);
                }
            }
        }
Пример #12
0
 /// <summary>
 /// LoadFromRaw 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);
 }
Пример #13
0
 /// <summary>
 /// Release the image and client objects.
 /// </summary>
 private void ReleaseObjects()
 {
     if (_releaseImageObject && _image != null)
     {
         _image.Dispose();
         _image = null;
     }
     if (_imageFileStream != null)
     {
         _imageFileStream.Dispose();
         _imageFileStream = null;
     }
     if (_client != null)
     {
         _client.CancelAsync();
         _client.Dispose();
         _client = null;
     }
 }
Пример #14
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);
            }
        }
Пример #15
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);
 }
Пример #16
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);
 }
Пример #17
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);
 }
Пример #18
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);
Пример #19
0
 /// <summary>
 /// Set the given image to clipboard.
 /// </summary>
 /// <param name="image"></param>
 protected virtual void SetToClipboardInt(RImage image)
 {
     throw new NotImplementedException();
 }
Пример #20
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);
Пример #21
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();
 }
Пример #22
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);
 }
Пример #23
0
 public override void DrawImage(RImage image, RRect destRect, RRect srcRect)
 {
     ReleaseHdc();
     _g.DrawImage(((ImageAdapter)image).Image, Utils.Convert(destRect), Utils.Convert(srcRect), GraphicsUnit.Pixel);
 }
Пример #24
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();
 }
Пример #25
0
 public override void DrawImage(RImage image, RRect destRect)
 {
     ReleaseHdc();
     _g.DrawImage(((ImageAdapter)image).Image, Utils.Convert(destRect));
 }
Пример #26
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());
            }
        }
Пример #27
0
 /// <summary>
 /// LoadFromRaw 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(FileInfo source)
 {
     try
     {
         if (source.Exists)
         {
             _imageFileStream = File.Open(source.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             _image = _htmlContainer.Adapter.ImageFromStream(_imageFileStream);
             _releaseImageObject = true;
         }
         ImageLoadComplete();
     }
     catch (Exception ex)
     {
         _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Failed to load image from disk: " + source, ex);
         ImageLoadComplete();
     }
 }