Exemple #1
0
		static SolidBrush GetBrush (Color color)
		{
			var cache = Platform.Instance.Cache<BrushKey, SolidBrush>(cacheKey);
			SolidBrush brush;
			lock (cache) {
				var key = new BrushKey (color.ToArgb ());
				if (!cache.TryGetValue (key, out brush)) {
					brush = new SolidBrush (color);
					cache.Add (key, brush);
				}
			}
			return brush;
		}
Exemple #2
0
		static Brush GetBrush (Color color, Generator generator)
		{
			var cache = generator.Cache<BrushKey, Brush>(cacheKey);
			Brush brush;
			lock (cache) {
				var key = new BrushKey (color.ToArgb ());
				if (!cache.TryGetValue (key, out brush)) {
					brush = new SolidBrush (color, generator);
					cache.Add (key, brush);
				}
			}
			return brush;
		}
Exemple #3
0
		static Pen GetPen (Generator generator, Color color, float thickness = 1f, DashStyle dashStyle = null)
		{
			var cache = generator.Cache<PenKey, Pen> (cacheKey);
			Pen pen;
			lock (cache) {
				var key = new PenKey (color.ToArgb (), thickness, dashStyle);
				if (!cache.TryGetValue (key, out pen)) {
					pen = new Pen (color, thickness, generator);
					if (dashStyle != null) pen.DashStyle = dashStyle;
					cache.Add (key, pen);
				}
			}
			return pen;
		}
Exemple #4
0
		/// <summary>
		/// Sets the pixel color at the specified coordinates.
		/// </summary>
		/// <param name="x">The x coordinate of the pixel to set.</param>
		/// <param name="y">The y coordinate of the pixel to set.</param>
		/// <param name="color">Color to set the pixel to.</param>
		public unsafe override void SetPixel(int x, int y, Color color)
		{
			var pos = (byte*)Data;
			pos += x * BytesPerPixel + y * ScanWidth;

			var col = TranslateArgbToData(color.ToArgb());
			if (BytesPerPixel == 4)
			{
				*((int*)pos) = col;
			}
			else if (BytesPerPixel == 3)
			{
				*(pos++) = (byte)(col & 0xFF);
				*(pos++) = (byte)((col >> 8) & 0xFF);
				*(pos++) = (byte)((col >> 16) & 0xFF);
			}
			else
				throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "This PixelFormat is not supported by SetPixel. Must be 3 or 4 bytes per pixel"));
		}