/// <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; }
/// <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); }
/// <summary> /// Get image to be used if HTML image load failed. /// </summary> public RImage GetLoadingFailedImage() { if (_errorImage == null) { var assembly = Assembly.LoadFrom(nameof(HtmlRenderer)); var stream = assembly.GetManifestResourceStream("TheArtOfDev.HtmlRenderer.Core.Utils.ImageError.png"); if (stream != null) { _errorImage = ImageFromStream(stream); } } return(_errorImage); }
public override void DrawImage(RImage image, RRect destRect) { _g.DrawImage(((ImageAdapter) image).Image, 1, new Rect(0, 0, image.Width, image.Height), Util.Convert(destRect)); }
/// <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); } }
public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) { //TODO: Implement texture brush return PerspexAdapter.Instance.GetSolidBrush(Util.Convert(Colors.Magenta)); //var brush = new ImageBrush(((ImageAdapter)image).Image); //brush.Stretch = Stretch.None; //brush.TileMode = TileMode.Tile; //brush.Viewport = Utils.Convert(dstRect); //brush.ViewportUnits = BrushMappingMode.Absolute; //brush.Transform = new TranslateTransform(translateTransformLocation.X, translateTransformLocation.Y); //brush.Freeze(); //return new BrushAdapter(brush); }
/// <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);
/// <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(); } }
public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) { return new BrushAdapter(new XTextureBrush(((ImageAdapter)image).Image, Utils.Convert(dstRect), Utils.Convert(translateTransformLocation))); }
/// <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); }
/// <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(); }
public override void DrawImage(RImage image, RRect destRect) { _g.DrawImage(((ImageAdapter)image).Image, Utils.ConvertRound(destRect)); }
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); } } }
public override void DrawImage(RImage image, RRect destRect, RRect srcRect) { CroppedBitmap croppedImage = new CroppedBitmap(((ImageAdapter)image).Image, new Int32Rect((int)srcRect.X, (int)srcRect.Y, (int)srcRect.Width, (int)srcRect.Height)); _g.DrawImage(croppedImage, Utils.ConvertRound(destRect)); }
public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) { var brush = new ImageBrush(((ImageAdapter)image).Image); brush.Stretch = Stretch.None; brush.TileMode = TileMode.Tile; brush.Viewport = Utils.Convert(dstRect); brush.ViewportUnits = BrushMappingMode.Absolute; brush.Transform = new TranslateTransform(translateTransformLocation.X, translateTransformLocation.Y); brush.Freeze(); return new BrushAdapter(brush); }
/// <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; } } }
public override void DrawImage(RImage image, RRect destRect) { ReleaseHdc(); _g.DrawImage(((ImageAdapter)image).Image, Utils.Convert(destRect)); }
protected override void SetToClipboardInt(RImage image) { Clipboard.SetImage(((ImageAdapter)image).Image); }
/// <summary> /// Get image to be used while HTML image is loading. /// </summary> public RImage GetLoadingImage() { if (_loadImage == null) { var stream = typeof(HtmlRendererUtils).GetTypeInfo().Assembly.GetManifestResourceStream("TheArtOfDev.HtmlRenderer.Core.Utils.ImageLoad.png"); if (stream != null) _loadImage = ImageFromStream(stream); } return _loadImage; }
protected override void SetToClipboardInt(RImage image) { //Do not crash, just ignore //TODO: implement image clipboard support }
/// <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); }
/// <summary> /// Set the given image to clipboard. /// </summary> /// <param name="image"></param> protected virtual void SetToClipboardInt(RImage image) { throw new NotImplementedException(); }
protected override void SaveToFileInt(RImage image, string name, string extension, RControl control = null) { var saveDialog = new SaveFileDialog(); saveDialog.Filter = "Images|*.png;*.bmp;*.jpg;*.tif;*.gif;*.wmp;"; saveDialog.FileName = name; saveDialog.DefaultExt = extension; var dialogResult = saveDialog.ShowDialog(); if (dialogResult.GetValueOrDefault()) { var encoder = Utils.GetBitmapEncoder(Path.GetExtension(saveDialog.FileName)); encoder.Frames.Add(BitmapFrame.Create(((ImageAdapter)image).Image)); using (FileStream stream = new FileStream(saveDialog.FileName, FileMode.OpenOrCreate)) encoder.Save(stream); } }
public override void DrawImage(RImage image, RRect destRect, RRect srcRect) { _g.DrawImage(((ImageAdapter)image).Image, Utils.Convert(destRect), Utils.Convert(srcRect), XGraphicsUnit.Point); }
/// <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); } } }
/// <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> /// 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()); } }
/// <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(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(); } }
public override void DrawImage(RImage image, RRect destRect, RRect srcRect) { _g.DrawImage(((ImageAdapter) image).Image, 1, Util.Convert(srcRect), Util.Convert(destRect)); }
/// <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; } }
/// <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); }