public static void DrawImage(Graphics g, Image image, ImageLayoutMode layoutMode, Rectangle rect) { // Graphics g = Graphics.FromHwnd(IntPtr.Zero); if (layoutMode == ImageLayoutMode.None) { Rectangle tempRect = new Rectangle(rect.X, rect.Y, image.Width, image.Height); g.SetClip(rect); g.DrawImage(image, tempRect); g.ResetClip(); } else if (layoutMode == ImageLayoutMode.Stretch) { g.DrawImage(image, rect); } else if (layoutMode == ImageLayoutMode.FitToWidth) { g.SetClip(rect); Size newSize = new Size(rect.Width, rect.Width * image.Height / image.Width); g.DrawImage(image, new Rectangle(rect.Location, newSize)); g.ResetClip(); } else if (layoutMode == ImageLayoutMode.FitToHeight) { g.SetClip(rect); Size newSize = new Size(rect.Height * image.Width / image.Height, rect.Height); g.DrawImage(image, new Rectangle(rect.Location, newSize)); g.ResetClip(); } }
/// <ToBeCompleted></ToBeCompleted> private static TextureBrush GetBrush(Image image, ImageLayoutMode imageLayout, float gamma, byte transparency, bool grayScale) { if (image == null) { throw new ArgumentNullException("image"); } BrushKey brushKey; brushKey.FillStyle = null; brushKey.Image = image; Brush brush = null; if (!_brushCache.TryGetValue(brushKey, out brush)) { // First, get ImageAttributes ImageAttributes imgAttribs = null; if (!_imageAttribsCache.TryGetValue(brushKey, out imgAttribs)) { imgAttribs = GdiHelpers.GetImageAttributes(imageLayout, gamma, transparency, grayScale); _imageAttribsCache.Add(brushKey, imgAttribs); } // Create Brush _rectBuffer.X = 0; _rectBuffer.Y = 0; _rectBuffer.Width = image.Width; _rectBuffer.Height = image.Height; brush = new TextureBrush(image, _rectBuffer, imgAttribs); // Add created brush to the BrushCache _brushCache.Add(brushKey, brush); } return((TextureBrush)brush); }
private void Construct() { // this fillStyle holds the image of the shape image = null; imageGrayScale = false; compressionQuality = 100; imageGamma = 1; imageLayout = ImageLayoutMode.Original; imageTransparency = 0; }
//private Image BrushImage { // get { // if (brushImage == null // && !NamedImage.IsNullOrEmpty(image) // && (image.Width >= 2 * Width || image.Height >= 2 * Height)) // brushImage = GdiHelpers.GetBrushImage(image.Image, Width, Height); // return brushImage; // } //} private void Construct(string resourceBaseName, Assembly resourceAssembly) { if (resourceBaseName == null) throw new ArgumentNullException("resourceBaseName"); System.IO.Stream stream = resourceAssembly.GetManifestResourceStream(resourceBaseName); if (stream == null) throw new ArgumentException(string.Format("'{0}' is not a valid resource in '{1}'.", resourceBaseName, resourceAssembly), "resourceBaseName"); var customimage = System.Drawing.Image.FromStream(stream); if (customimage == null) throw new ArgumentException(string.Format("'{0}' is not a valid image resource.", resourceBaseName), "resourceBaseName"); this.resourceName = resourceBaseName; this.resourceAssembly = resourceAssembly; image = new NamedImage(customimage, "customimage"); // this fillStyle holds the image of the shape imageGrayScale = false; compressionQuality = 100; imageGamma = 1; imageLayout = ImageLayoutMode.Original; imageTransparency = 0; //FitShapeToImageSize(); }
/// <override></override> protected override void LoadFieldsCore(IRepositoryReader reader, int version) { base.LoadFieldsCore(reader, version); imageLayout = (ImageLayoutMode)reader.ReadByte(); imageTransparency = reader.ReadByte(); imageGamma = reader.ReadFloat(); compressionQuality = reader.ReadByte(); imageGrayScale = reader.ReadBool(); string name = reader.ReadString(); Image img = reader.ReadImage(); if (name != null && img != null) image = new NamedImage(img, name); transparentColor = Color.FromArgb(reader.ReadInt32()); }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is CustomPictureBase) { CustomPictureBase src = (CustomPictureBase)source; if (!NamedImage.IsNullOrEmpty(src.Image)) Image = src.Image.Clone(); imageGrayScale = src.GrayScale; imageLayout = src.ImageLayout; imageGamma = src.GammaCorrection; imageTransparency = src.Transparency; transparentColor = src.TransparentColor; compressionQuality = src.compressionQuality; } }
/// <ToBeCompleted></ToBeCompleted> public static TextureBrush GetBrush(Image image, ImageLayoutMode imageLayout, float gamma, byte transparency, bool grayScale) { if (image == null) throw new ArgumentNullException("image"); BrushKey brushKey; brushKey.FillStyle = null; brushKey.Image = image; Brush brush = null; brushCache.TryGetValue(brushKey, out brush); if (!(brush is TextureBrush)) { // First, get ImageAttributes ImageAttributes imgAttribs = null; imageAttribsCache.TryGetValue(brushKey, out imgAttribs); if (imgAttribs == null) { imgAttribs = GdiHelpers.GetImageAttributes(imageLayout, gamma, transparency, grayScale); imageAttribsCache.Add(brushKey, imgAttribs); } // Create Brush rectBuffer.X = 0; rectBuffer.Y = 0; rectBuffer.Width = image.Width; rectBuffer.Height = image.Height; brush = new TextureBrush(image, rectBuffer, imgAttribs); // add created brush to the BrushCache if (brushCache.ContainsKey(brushKey)) brushCache[brushKey] = brush; else brushCache.Add(brushKey, brush); } return (TextureBrush)brush; }
void IEntity.LoadFields(IRepositoryReader reader, int version) { name = reader.ReadString(); if (version >= 3) title = reader.ReadString(); if (version >= 4) securityDomainName = reader.ReadChar(); size.Width = reader.ReadInt32(); size.Height = reader.ReadInt32(); backColor = Color.FromArgb(reader.ReadInt32()); targetColor = Color.FromArgb(reader.ReadInt32()); string imgName = reader.ReadString(); Image img = reader.ReadImage(); if (img != null) backImage = new NamedImage(img, imgName); imageLayout = (ImageLayoutMode)reader.ReadByte(); imageGamma = reader.ReadFloat(); imageTransparency = reader.ReadByte(); imageGrayScale = reader.ReadBool(); imageTransparentColor = Color.FromArgb(reader.ReadInt32()); }