/// <summary> /// Edits the given value. /// </summary> /// <param name="context">Context infromation.</param> /// <param name="provider">Service provider.</param> /// <param name="value">Value to be edited.</param> /// <returns>An edited value.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (service == null) { return(value); } if (_colorUI == null) { _colorUI = new ColorUIWrapper(this); } Color xnacolor = (Color)value; _colorUI.Start(service, System.Drawing.Color.FromArgb(xnacolor.A, xnacolor.R, xnacolor.G, xnacolor.B)); service.DropDownControl(_colorUI.Control); if ((_colorUI.Value != null) /*&& (((Color)_colorUI.Value) != Color.Empty)*/) { //value = _colorUI.Value; System.Drawing.Color rescolor = (System.Drawing.Color)_colorUI.Value; value = new Color(rescolor.R, rescolor.G, rescolor.B, rescolor.A); } _colorUI.End(); } return(value); }
public override void PaintValue(PaintValueEventArgs e) { if (e.Value is Color && ((Color)e.Value).A <= byte.MaxValue) { var xnacolor = (Color)e.Value; System.Drawing.Color syscolor = System.Drawing.Color.FromArgb(xnacolor.A, xnacolor.R, xnacolor.G, xnacolor.B); Graphics graphics = e.Graphics; using (var brush = new SolidBrush(System.Drawing.Color.DarkGray)) { graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 1, 4, 4)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 9, e.Bounds.Y + 1, 4, 4)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 17, e.Bounds.Y + 1, 2, 4)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 5, e.Bounds.Y + 5, 4, 4)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 13, e.Bounds.Y + 5, 4, 4)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + 9, 4, 3)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 9, e.Bounds.Y + 9, 4, 3)); graphics.FillRectangle(brush, new Rectangle(e.Bounds.X + 17, e.Bounds.Y + 9, 2, 3)); } using (var brush = new SolidBrush(syscolor)) { graphics.FillRectangle(brush, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height - 1)); } } if (e.Value is System.Drawing.Color) { base.PaintValue(e); } }
internal void WriteToFile(string fullFilename) { byte[] outputData = new byte[Width * Height * 4]; DXTexture.GetData <byte> (outputData); int scale = 1; System.Drawing.Bitmap bm = new System.Drawing.Bitmap(Width * scale, Height * scale, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int pixelIndex = (x + y * Width) * 4; System.Drawing.Color col = System.Drawing.Color.FromArgb(0xFF, outputData [pixelIndex + 0], outputData [pixelIndex + 1], outputData [pixelIndex + 2]); for (int y2 = 0; y2 < scale; y2++) { for (int x2 = 0; x2 < scale; x2++) { bm.SetPixel(x * scale + x2, y * scale + y2, col); } } } } bm.Save(fullFilename, System.Drawing.Imaging.ImageFormat.Png); }
public void Draw(SpriteBatch spriteBatch) { Vector2 foodVector = foodLocation; System.Drawing.Color tintColor = System.Drawing.Color.White; var foodRectangle = food.CurrentRectangle; spriteBatch.Draw(characterSheetTexture, foodVector, foodRectangle, Color.White); }
public void Draw(SpriteBatch spriteBatch) { Vector2 topLeftOfSprite = new Vector2(this.X, this.Y); System.Drawing.Color tintColor = System.Drawing.Color.White; var sourceRectangle = currentAnimation.CurrentRectangle; spriteBatch.Draw(characterSheetTexture, topLeftOfSprite, sourceRectangle, Color.White); }
Color GetColorAt(int x, int y) { System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(x, y, 1, 1); try { using (Graphics g = Graphics.FromImage(bmp)) g.CopyFromScreen(bounds.Location, System.Drawing.Point.Empty, bounds.Size); } catch (Win32Exception e) { // Occurs when administrator privilege requesting window pops out. return(Color.Transparent); } System.Drawing.Color color = bmp.GetPixel(0, 0); return(new Color(new Vector4(color.R, color.G, color.B, color.A) / 255.0f)); }
public void SetBackgroundImage(Bitmap bmp) { Color[] pixels = new Color[bmp.Width * bmp.Height]; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { System.Drawing.Color c = bmp.GetPixel(x, y); pixels[(y * bmp.Width) + x] = new Color(c.R, c.G, c.B, c.A); } } backgroundImage = new Texture2D( GraphicsDevice, bmp.Width, bmp.Height, true, SurfaceFormat.Color); backgroundImage.SetData(pixels); }
private Texture2DContent BuildTextureContent(byte[] buffer) { var bitmap = new Bitmap(new MemoryStream(buffer)); var bitmapContent = new PixelBitmapContent <Color>(bitmap.Width, bitmap.Height); for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { System.Drawing.Color from = bitmap.GetPixel(i, j); //System.Drawing.Color to Microsoft.Xna.Framework.Color var to = new Color(from.R, from.G, from.B, from.A); bitmapContent.SetPixel(i, j, to); } } return(new Texture2DContent { Mipmaps = new MipmapChain(bitmapContent) }); }
public Color XNAColor(System.Drawing.Color color) => new Color(color.R, color.G, color.B, color.A);
private void PaintLayer(float weight) { // Cursor Position on Landscape Vector2 position = new Vector2(MouseCoords.X - ((float)BrushSize / 2), MouseCoords.Z - ((float)BrushSize / 2)); // Rectangle to draw on Rectangle rec = new Rectangle((int)position.X, (int)position.Y, BrushSize, BrushSize); // Make sure we are not larger/smaller then the actual landscapes paint mask texture if (rec.Right > PaintMask1.Width || rec.Left > PaintMask1.Width || rec.Top > PaintMask1.Height || rec.Bottom > PaintMask1.Height || rec.Right < 0 || rec.Left < 0 || rec.Top < 0 || rec.Bottom < 0) { return; } Color pixel = Color.Transparent; // Brush texture to use Bitmap brush = new Bitmap(Resource1.RoundBrush, BrushSize, BrushSize); // Build a color array to grab our pixels off our brush texture Color[] col = new Color[brush.Width * brush.Height]; for (int x = 0; x < brush.Width; x++) { for (int y = 0; y < brush.Height; y++) { int index = x + y * brush.Width; System.Drawing.Color c = brush.GetPixel(x, y); switch (CurrentPaintLayer) { case 0: pixel.R += (byte)(c.R / weight); break; case 1: pixel.G += (byte)(c.G / weight); break; case 2: pixel.B += (byte)(c.B / weight); break; case 3: pixel.A += (byte)(c.A / weight); break; } col[index] = new Color(pixel.R, pixel.G, pixel.B, pixel.A); } } #region old routine //for (int x = 0; x < BrushSize; x++) //{ // for (int y = 0; y < BrushSize; y++) // { // int index = x + y*BrushSize; // int red = col[index].R + pixel.R; // Layer1 // int green = col[index].G + pixel.G; // Layer2 // int blue = col[index].B + pixel.B; // Layer3 // int alpha = col[index].A + pixel.A; // Layer4 // // Apply our new found color goodness to our pixel // col[index] = new Color(red, green, blue, alpha); // } //} #endregion old routine // Unset the [4]th samplers (0-based) texture so we can set data to it on the graphics device GraphicsDevice.Textures[4] = null; // Set the new paint mask texture data on the gpu PaintMask1.SetData(0, rec, col, 0, col.Length); }
public static Color ConvertSystemColorToXNA(System.Drawing.Color color) { return(new Color(color.R, color.G, color.B, color.A)); }
public static Color ToXNAColor(this System.Drawing.Color cl) { return(new Color(cl.R, cl.G, cl.B, cl.A)); }
/// <summary>Determines the current water color to use for the given location.</summary> /// <param name="location">The location to check.</param> /// <returns>The color to use for this location's water. Null if no custom color currently exists for this location.</returns> private static Color?GetCustomWaterColor(GameLocation location) { if (location.Map.Properties.TryGetValue(MapPropertyName, out var mapPropertyObject)) //if the location has a non-null map property { string mapProperty = mapPropertyObject.ToString() ?? ""; //get the map property as a string string[] args = mapProperty.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //split the property value along spaces and remove any blank args Color?colorToUse = null; switch (args.Length) //based on the number of args... { case 0: //if no args exist, treat it as blank (don't modify the color) break; case 1: //if 1 arg exists, treat it as a color name if (Enum.TryParse(args[0], true, out KnownColor namedColor)) //if this is a recognized color name { System.Drawing.Color systemColor = System.Drawing.Color.FromKnownColor(namedColor); //convert it to a System.Drawing.Color colorToUse = new Color(systemColor.R, systemColor.G, systemColor.B, systemColor.A); //convert it to an XNA color and use it } else { Monitor.LogOnce($"Failed to parse map property {MapPropertyName}. Value: \"{mapProperty}\". It appears to be an unrecognized color name.", LogLevel.Debug); } break; case 3: //if 3 args exist, treat it as an RGB value if (byte.TryParse(args[0], out byte r) && byte.TryParse(args[1], out byte g) && byte.TryParse(args[2], out byte b)) //if the args parse into bytes successfully (values from 0-255) { colorToUse = new Color(r, g, b, 0.5f); //convert it to an XNA color and use it (default to 50% transprency, imitating most Stardew water colors) } else { Monitor.LogOnce($"Failed to parse map property {MapPropertyName}. Value: \"{mapProperty}\". It appears to be an invalid RGB value.", LogLevel.Debug); } break; case 4: //if 4 args exist, treat it as an RGBA value if (byte.TryParse(args[0], out r) && byte.TryParse(args[1], out g) && byte.TryParse(args[2], out b) && byte.TryParse(args[3], out byte a)) //if the args parse into bytes successfully (values from 0-255) { colorToUse = new Color(r, g, b, a); //convert it to an XNA color and use it } else { Monitor.LogOnce($"Failed to parse map property {MapPropertyName}. Value: \"{mapProperty}\". It appears to be an invalid RGBA value.", LogLevel.Debug); } break; default: //invalid number of args Monitor.Log($"Failed to parse map property {MapPropertyName}. Value: \"{mapProperty}\". It appears to have an invalid number of arguments.", LogLevel.Debug); break; } if (colorToUse != null) //if map property exists and was parsed successfully { if (Monitor.IsVerbose) { Monitor.Log($"Overriding water color based on map property {MapPropertyName}. Location: {location.Name}. Property value: {mapProperty}.", LogLevel.Alert); } return(colorToUse.Value); } } return(null); //no valid map property found; return no color }