Spicy Chicken GDI in C#
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spicy Chicken GDI in C#相关的知识,希望对你有一定的参考价值。
1.Draw Directly XXXX ……
2.Memory + DrawImage XXX > 5fps
3.Memory + BitBlt XX > 15fps
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; namespace Yozora { public struct Dot { public float X, Y; public float Vx, Vy; public float Radius; public Color Color; static Random random = new Random((int)DateTime.Now.ToBinary()); public Dot(int width, int height, Color color) { X = (float)random.NextDouble() * width; Y = (float)random.NextDouble() * height; Vx = -0.5f + (float)random.NextDouble(); Vy = -0.5f + (float)random.NextDouble(); Radius = (float)random.NextDouble() * 2; Color = color; } } public class DotMgr { private Dot[] dot_array_; //the width of lines private Int32 b_ = 1; //the quanlity of dots private float d_ = 0.2f; //the origin and bitmap graphics private Graphics dst_g_, mmr_g_; // private Bitmap m_; //width private Int32 w_ = 1920; //height private Int32 h_ = 1200; //the limit of fps private Int32 f_ = 24; //the quanlity of stars private float s_ = 0.2f; //the lines of stars private Int32 l_ = 5; private IntPtr mmr_dc_ = IntPtr.Zero; private IntPtr dst_dc_ = IntPtr.Zero; public bool ok = true; public Inf Init(Graphics g, Int32 width, Int32 height, Int32 frame, float stars, float dots) { dst_g_ = g; w_ = width; h_ = height; f_ = frame; s_ = stars; d_ = dots; m_ = new Bitmap(w_, h_); mmr_g_ = Graphics.FromImage(m_); dst_g_.Clear(Color.Black); mmr_dc_ = mmr_g_.GetHdc(); dst_dc_ = dst_g_.GetHdc(); mmr_g_.ReleaseHdc(); return new Inf(0, "success init."); } public void CreateDots() { } public Inf DrawStar() { Inf inf = new Inf(2, "start drawing"); mmr_g_.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 0 ,0)), 0, 0, w_, h_); Int32 x, y, r1, r2; Int32 angle = 180 / l_; Int32 l = l_ * 2; Point[] star = new Point[l+1]; Color color; Pen p; Random rnd = new Random(); for (Int32 i = 0; i < w_ * s_; ++i) { x = rnd.Next(10, w_ - 10); y = rnd.Next(10, h_ - 10); // ? r1 = rnd.Next(4, 7); r2 = rnd.Next(8, 12); color = Color.FromArgb(240, rnd.Next(1, 254), rnd.Next(1, 254), rnd.Next(1, 254)); p = new Pen(color, b_); for (Int32 j = 0; j < l+1; ++j) { star[j].X = Convert.ToInt32(Math.Round(j % 2 == 0 ? (x + r1 * Math.Cos(j * 3.14159 / l_)) : (x + r2 * Math.Cos(j * 3.14159 / l_)), 2, MidpointRounding.AwayFromZero)); star[j].Y = Convert.ToInt32(Math.Round(j % 2 == 0 ? (y + r1 * Math.Sin(j * 3.14159 / l_)) : (y + r2 * Math.Sin(j * 3.14159 / l_)), 2, MidpointRounding.AwayFromZero)); } mmr_g_.DrawLines(p, star); if (rnd.Next(0, 100) > 50) mmr_g_.FillPolygon(new SolidBrush(color), star); } ok = true;
//spciy chicken W32.SelectObject(mmr_dc_, m_.GetHbitmap()); W32.BitBlt(dst_dc_, 0, 0, w_, h_, mmr_dc_, 0, 0, W32.SRCCOPY); return new Inf(1, "draw successfully!"); } } }
以上是关于Spicy Chicken GDI in C#的主要内容,如果未能解决你的问题,请参考以下文章