public BrushAdapter(RImage image, RRect dstRect, RPoint translateTransformLocation) { isImage = true; this.image = image.ToImageA(); image_dstRect = dstRect; image_translateTransformLocation = translateTransformLocation; }
/// <summary> /// store added image /// </summary> /// <param name="image"></param> /// <returns></returns> public async Task <RServiceResult <RImage> > Store(RImage image) { _context.GeneralImages.Add(image); await _context.SaveChangesAsync(); return(new RServiceResult <RImage>(image)); }
private void SettingImageButton_Click(object sender, RoutedEventArgs e) { //打开文件对话框,选择图片,复制到程序图片文件夹 string imgFolderPath = Directory.GetCurrentDirectory() + @"\Images\"; Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.InitialDirectory = imgFolderPath; ofd.DefaultExt = ".*"; ofd.Filter = "图片文件|*.bmp;*.jpg;*.png;*.gif"; if (ofd.ShowDialog() == true) { string sourceImagePath = ofd.FileName; RImage newImage = new RImage(new FileInfo(sourceImagePath)); string fileName = ofd.SafeFileName; string newImagePath = imgFolderPath + fileName; int i = 1; while (System.IO.File.Exists(newImagePath))//已经存在相同名字 { string[] ss = fileName.Split('.'); newImage.ImageName = ss[0] + "(" + i + ")." + ss[1]; newImagePath = imgFolderPath + newImage.ImageName; newImage.Path = newImagePath; i++; } System.IO.File.Copy(sourceImagePath, newImagePath, true); ImageResourceCollection.Add(newImage); this.Logout("Image FullPath:" + newImagePath); } }
public static IEnumerable <RImage> GetImageResources() { //加载图片资源 List <RImage> imgs = new List <RImage>(); //文件夹下图片 string curDirPath = Directory.GetCurrentDirectory() + @"\Images"; //若不存在文件夹则先创建 if (!Directory.Exists(curDirPath)) { Directory.CreateDirectory(curDirPath); } DirectoryInfo di = new DirectoryInfo(curDirPath); FileInfo[] fis = di.GetFiles(); foreach (FileInfo fi in fis) { string ext = fi.Extension.ToLower(); if (ext.IndexOf("jpg") == -1 && ext.IndexOf("png") == -1 && ext.IndexOf("gif") == -1 && ext.IndexOf("bmp") == -1) { continue; } else { RImage image = new RImage(fi); imgs.Add(image); } } return(imgs); }
public DrawImageCommand(RImage image, RRect rect1, RRect rect2, GraphicsUnit gu = GraphicsUnit.World) { Image = image; Rect1 = rect1; Rect2 = rect2; GraphicsUnit = gu; }
public int WidthOf(char cChar, int iGlyphType) { int iReturn = 0; try { if ((int)cChar == 9) { iReturn = iPixelsTab; //tab } else if (cChar == ' ') { iReturn = iPixelsSpace; //space } else if ((int)cChar == 13) { iReturn = 0; //CR (LF is 10, and ignored) } else { //animarrGlyphType[iGlyphType].GotoFrame((long)cChar); RImage riNow = Glyph(cChar, iGlyphType); if (riNow != null) { iReturn = riNow.iWidth; //animarrGlyphType[iGlyphType].riFrame.iWidth; } } } catch (Exception exn) { iReturn = 0; RReporting.ShowExn(exn, "", String.Format("RFont WidthOf({0},{1})", char.ToString(cChar), GlyphTypeToString(iGlyphType))); } return(iReturn); }
} //end Glyph(cNow,iGlyphType) public bool TypeOnOneLine(ref RImage riDest, int xDest, int yDest, string sText, int iGlyphType) { //TODO: really, this should return a rect (e.g. html-style stretching of container) bool bGood = true; bool bSpacing; int xNow = xDest; try { int iCursor = 0; for (int iChar = 0; iChar < sText.Length; iChar++) { RImage riNow = Glyph(sText[iChar], iGlyphType); if (xNow + riNow.Width < riDest.Width) { if (!RString.IsWhiteSpace(sText[iChar])) { riDest.DrawFromSmallerWithoutCropElseCancel(xNow, yDest, riNow, RImage.DrawMode_AlphaHardEdgeColor_KeepDestAlpha); } } else { break; } xNow += WidthOf(sText[iChar], iGlyphType); } } catch (Exception exn) { RReporting.ShowExn(exn, "", "TypeOnOneLine(...,\"" + RString.ElipsisIfOver(sText, 10) + "\")"); bGood = false; } return(bGood); } //end TypeOnOneLine
} //end FromImage public void ShowAsciiTable(RImage riTarget, int xAt, int yAt) { RReporting.sLastFile = Normal.SourceToRegExString(); try { IPoint ipAt = new IPoint(xAt, yAt); int lChar = 0; for (int yChar = 0; yChar < 16; yChar++) { ipAt.X = xAt; for (int xChar = 0; xChar < 16; xChar++) { animarrGlyphType[RFont.GlyphTypeNormal].GotoFrame(lChar); RImage.DrawToLargerNoClipBitdepthInsensitive(ref riTarget, ref ipAt, ref animarrGlyphType[RFont.GlyphTypeNormal].riFrame.byarrData, animarrGlyphType[RFont.GlyphTypeNormal].riFrame.Width, animarrGlyphType[RFont.GlyphTypeNormal].riFrame.Height, 1); ipAt.X += animarrGlyphType[RFont.GlyphTypeNormal].riFrame.Width; lChar++; } ipAt.Y += animarrGlyphType[RFont.GlyphTypeNormal].riFrame.Height; } } catch (Exception exn) { RReporting.ShowExn(exn, "", "ShowAsciiTable"); } } //end ShowAsciiTable
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)); }
private void AddControlImage(XmlElement xElementRoot, RImage control) { this.AddAtributo(xElementRoot, "BorderColor", control.边界颜色.Name); this.AddAtributo(xElementRoot, "BorderWidth", control.边界线宽.ToString()); this.AddAtributo(xElementRoot, "FileName", control.文件); this.AddAtributo(xElementRoot, "Stretch", control.Stretch.ToString()); }
/// <summary> /// Generated Cropped Image Based On ThumbnailCoordinates For Notes /// </summary> /// <param name="id"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public async Task <RServiceResult <RImage> > GenerateCroppedImageBasedOnThumbnailCoordinates(Guid id, decimal left, decimal top, decimal width, decimal height) { try { RPictureFile rPictureFile = await _context.PictureFiles .Where(p => p.Id == id) .SingleOrDefaultAsync(); int adjustedImageWidth = (int)(width * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth); if (adjustedImageWidth > rPictureFile.ThumbnailImageWidth) { adjustedImageWidth = rPictureFile.ThumbnailImageWidth; } int adjustedImageHeight = (int)(height * adjustedImageWidth / width); int adjusttedLeft = (int)(left * adjustedImageWidth / width); int adjusttedTop = (int)(top * adjustedImageHeight / height); string normalImagePath = GetImagePath(rPictureFile, "norm").Result; using (Image targetImage = new Bitmap(adjustedImageWidth, adjustedImageHeight)) { using (Graphics g = Graphics.FromImage(targetImage)) { using (Image img = Image.FromFile(normalImagePath)) { g.DrawImage(img, new Rectangle(0, 0, adjustedImageWidth, adjustedImageHeight), (int)(left * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth), (int)(top * rPictureFile.NormalSizeImageHeight / rPictureFile.ThumbnailImageHeight), (int)(width * rPictureFile.NormalSizeImageWidth / rPictureFile.ThumbnailImageWidth), (int)(height * rPictureFile.NormalSizeImageHeight / rPictureFile.ThumbnailImageHeight), GraphicsUnit.Pixel, new ImageAttributes() ); } } using (MemoryStream ms = new MemoryStream()) { targetImage.Save(ms, ImageFormat.Jpeg); ms.Position = 0; RServiceResult <RImage> res = await _simpleImageStorage.Add(null, ms, $"{Path.GetFileNameWithoutExtension(rPictureFile.OriginalFileName)}-cropped-{left}-{top}-{width}-{height}.jpg", "CroppedImages"); if (string.IsNullOrEmpty(res.ExceptionString)) { RImage image = res.Result; _context.GeneralImages.Add(image); await _context.SaveChangesAsync(); return(new RServiceResult <RImage>(image)); } return(res); } } } catch (Exception exp) { return(new RServiceResult <RImage>(null, exp.ToString())); } }
public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) { var brush = new TextureBrush(((IImageAdapter)image).Image); //brush. brush.Transform = Matrix.FromTranslation((float)translateTransformLocation.X, (float)translateTransformLocation.Y); return(new BrushAdapter(brush, true)); }
public bool SetHsva(double h, double s, double v, double aTo1) { byte r, g, b, a; a = RConvert.ToByte(aTo1 * 255.0); RImage.HsvToRgb(out r, out g, out b, ref h, ref s, ref v); return(SetArgb(a, r, g, b)); }
} //end SetArgb (primary overload) public bool SetHsva(float h, float s, float v, float aTo1) { byte r, g, b, a; a = RConvert.ToByte(aTo1 * 255.0f); RImage.HsvToRgb(out r, out g, out b, ref h, ref s, ref v); return(SetArgb(a, r, g, b)); }
protected override RImage ConvertImageInt(object image) { if (image is Stream stream) { MemoryStream ms = null; try { long originalPosition; if (!stream.CanSeek) { ms = new MemoryStream(); stream.CopyTo(ms); originalPosition = 0; stream = ms; } else { originalPosition = stream.Position; } RImage adapter = null; // todo: remove when Eto supports extracting frames from GIF files directly. // use platform-specific adapters to support image animation if (global::Eto.Platform.Instance.Supports <IImageAdapter>()) { var imageAdapter = global::Eto.Platform.Instance.Create <IImageAdapter>(); if (imageAdapter.Load(stream)) { adapter = (RImage)imageAdapter; } } if (adapter != null) { return(adapter); } stream.Position = originalPosition; return(new ImageAdapter(new Bitmap(stream))); } finally { ms?.Dispose(); } } if (image is Image bitmap) { return(new ImageAdapter(bitmap)); } if (image is RImage rimage) { return(rimage); } return(null); }
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.DestinationRect = new RelativeRect(Util.Convert(dstRect).Translate(Util.Convert(translateTransformLocation) - new Point()), RelativeUnit.Absolute); return(new BrushAdapter(brush)); }
/// <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); }
public int GlyphHeight(int iGlyphType) { int iReturn = 0; RImage riNow = Glyph('|', iGlyphType); if (riNow != null) { iReturn = riNow.Height; } return(iReturn); }
/// <summary> /// Get Image Storage Path /// </summary> /// <param name="image"></param> /// <returns></returns> public RServiceResult <string> GetImagePath(RImage image) { try { return(new RServiceResult <string>(Path.Combine(ImageStoragePath, image.FolderName, image.StoredFileName))); } catch (Exception exp) { return(new RServiceResult <string>(null, exp.ToString())); } }
public bool Render(ref RImage riDest, int x, int y, string sText, int iGlyphType) { try { rectDefault.Set(x, y, riDest.Width - x, riDest.Height - y); return(Render(ref riDest, rectDefault, sText, iGlyphType)); } catch (Exception exn) { RReporting.ShowExn(exn, "accessing destination graphics", "RFont Render"); } return(false); }
private void ProcessImage(XmlElement xElementControl, RImage control) { XmlAttribute attribute = xElementControl.Attributes["Image"]; if (attribute == null) { } control.边界线宽 = this.GetInteger(xElementControl.Attributes, "BorderWidth"); control.边界颜色 = Color.FromName(this.GetString(xElementControl.Attributes, "BorderColor")); control.Stretch = this.GetBoolean(xElementControl.Attributes, "Stretch"); control.文件 = this.GetString(xElementControl.Attributes, "FileName"); }
/// <summary> /// Draw the background image at the required location repeating it over the Y axis.<br/> /// Adjust location to top if starting location doesn't include all the range (adjusted to center or bottom). /// </summary> private static void DrawRepeatY(RGraphics g, RImage image, RRect rectangle, RRect srcRect, RRect destRect, RSize imgSize) { while (destRect.Y > rectangle.Y) { destRect.Y -= imgSize.Height; } using (var brush = g.GetTextureBrush(image, srcRect, destRect.Location)) { g.DrawRectangle(brush, destRect.X, rectangle.Y, srcRect.Width, rectangle.Height); } }
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> /// store added image /// </summary> /// <param name="image"></param> /// <returns></returns> public async Task <RServiceResult <RImage> > Store(RImage image) { try { _context.GeneralImages.Add(image); await _context.SaveChangesAsync(); return(new RServiceResult <RImage>(image)); } catch (Exception exp) { return(new RServiceResult <RImage>(null, exp.ToString())); } }
public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) { //TODO: Implement texture brush return(AvaloniaAdapter.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> /// 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(); } }
public bool TypeHTML(ref RImage riDest, ref IPoint ipAt, IRect irectReturn, string sText, bool bVisible) { int iNextTag; int iLength; bool bGood = true; try { //TODO: finish TypeHTML } catch (Exception exn) { RReporting.ShowExn(exn, "", "TypeHTML(...,\"" + sText + "\",...)"); bGood = false; } return(bGood); }
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); } } }
/// <summary> /// Draw the background image of the given box in the given rectangle.<br/> /// Handle background-repeat and background-position values. /// </summary> /// <param name="g">the device to draw into</param> /// <param name="box">the box to draw its background image</param> /// <param name="imageLoadHandler">the handler that loads image to draw</param> /// <param name="rectangle">the rectangle to draw image in</param> public static void DrawBackgroundImage(RGraphics g, CssBox box, //ImageLoadHandler imageLoadHandler, RImage image, RRect imageRectangle, RRect rectangle ) { // image size depends if specific rectangle given in image loader var imgSize = new RSize( imageRectangle == RRect.Empty ? image.Width : imageRectangle.Width, imageRectangle == RRect.Empty ? image.Height : imageRectangle.Height); // get the location by BackgroundPosition value var location = GetLocation(box.BackgroundPosition, rectangle, imgSize); var srcRect = imageRectangle == RRect.Empty ? new RRect(0, 0, imgSize.Width, imgSize.Height) : new RRect(imageRectangle.Left, imageRectangle.Top, imgSize.Width, imgSize.Height); // initial image destination rectangle var destRect = new RRect(location, imgSize); // need to clip so repeated image will be cut on rectangle var lRectangle = rectangle; lRectangle.Intersect(g.GetClip()); g.PushClip(lRectangle); switch (box.BackgroundRepeat) { case "no-repeat": g.DrawImage(image, destRect, srcRect); break; case "repeat-x": DrawRepeatX(g, image, rectangle, srcRect, destRect, imgSize); break; case "repeat-y": DrawRepeatY(g, image, rectangle, srcRect, destRect, imgSize); break; default: DrawRepeat(g, image, rectangle, srcRect, destRect, imgSize); break; } g.PopClip(); }
/// <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; } } }