⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ut.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
字号:
using System;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Collections;
using System.Drawing;

using gowk.utility.Exception;

namespace gowk.controls
{
	/// <summary>
	/// UT 的摘要说明。
	/// </summary>
	public class UT
	{
		public static GraphicsPath CreateLargeRoundGraphicsPath(Rectangle rect)
		{
			int l=rect.Left;
			int t=rect.Top;
			int r=rect.Right;
			int b=rect.Bottom;	
			Point[] points = {	
								 new Point(l+0,t+4),
								 new Point(l+1,t+3),
								 new Point(l+2,t+2),
								 new Point(l+3,t+1),
								 new Point(l+4,t+0),

								 new Point(r-4,t+0),
								 new Point(r-3,t+1),
								 new Point(r-2,t+2),
								 new Point(r-1,t+3),
								 new Point(r-0,t+4),

								 new Point(r-0,b-4),
								 new Point(r-1,b-3),
								 new Point(r-2,b-2),
								 new Point(r-3,b-1),
								 new Point(r-4,b-0),

								 new Point(l+4,b-0),
								 new Point(l+3,b-1),
								 new Point(l+2,b-2),
								 new Point(l+1,b-3),
								 new Point(l+0,b-4),
								 
								 new Point(l+0,t+4)
							 };
			GraphicsPath gp=new GraphicsPath();
			gp.AddLines(points);
			return gp;
		}
		public static GraphicsPath CreateSmallRoundGraphicsPath(Rectangle rect)
		{
			int l=rect.Left;
			int t=rect.Top;
			int r=rect.Right;
			int b=rect.Bottom;	
			Point[] points = {	
								 new Point(l+0,t+2),
								 new Point(l+1,t+1),
								 new Point(l+2,t+0),

								 new Point(r-2,t+0),
								 new Point(r-1,t+1),
								 new Point(r-0,t+2),

								 new Point(r-0,b-2),
								 new Point(r-1,b-1),
								 new Point(r-2,b-0),

								 new Point(l+2,b-0),
								 new Point(l+1,b-1),
								 new Point(l+0,b-2),
								 
								 new Point(l+0,t+2)
							 };
			GraphicsPath gp=new GraphicsPath();
			gp.AddLines(points);
			return gp;
		}
		
		public static Region BitmapToRegion(Bitmap bitmap, Color transparencyColor)
		{
			if (bitmap == null)
				throw new ArgumentNullException("Bitmap", "Bitmap cannot be null!");

			int height = bitmap.Height;
			int width = bitmap.Width;

			GraphicsPath path = new GraphicsPath();

			for (int j=0; j<height; j++ )
				for (int i=0; i<width; i++)
				{
					if (bitmap.GetPixel(i, j) == transparencyColor)
						continue;

					int x0 = i;

					while ((i < width) && (bitmap.GetPixel(i, j) != transparencyColor))
						i++;

					path.AddRectangle(new Rectangle(x0, j, i-x0, 1));
				}

			Region region = new Region(path);
			path.Dispose();
			return region;
		}
		public static Icon ConvertImage2Icon(Image image)
		{
			Image img=image.GetThumbnailImage(24,24,null,IntPtr.Zero);
			Bitmap bm=img as Bitmap;
			//	if(bm==null)bm=new Bitmap(img);
			//	if(bm==null)return;
			IntPtr p=bm.GetHicon();
			return Icon.FromHandle(p);
		}
		public static Image GetDisableImage(Image image)
		{
			Bitmap bm=new Bitmap(image.Width,image.Height);
			using(Graphics g=Graphics.FromImage(bm))
			{
				System.Windows.Forms.ControlPaint.DrawImageDisabled(g,image,0,0,Color.Transparent);
			}
			return bm;
		}
		public static void DrawImage(Graphics g,Image img,Rectangle r,StretchOption opt)
		{
				if(img==null)return;
			try
			{
				GraphicsState state=g.Save();
				g.SetClip(r);
				switch(opt)
				{
					case StretchOption.HRepeat:
						for(int i=r.X;i<r.Right;i+=img.Width)
							g.DrawImage(img,i,r.Y,img.Width,r.Height);
						break;
					case StretchOption.VRepeat:
						for(int i=r.Top;i<r.Bottom;i+=img.Height)
						{
							g.DrawImage(img,r.X,i,img.Width,img.Height);
						}
						break;
					case StretchOption.HStretch:
						for(int i=r.Y;i<r.Bottom;i+=img.Height)
							g.DrawImage(img,r.X,i,r.Width,img.Height);
						break;
					case StretchOption.VStretch:
						for(int i=r.X;i<r.Right;i+=img.Width)
							g.DrawImage(img,i,r.Y,img.Width,r.Height);
						break;
					case StretchOption.Scaled:
						g.DrawImage(img,r);
						break;
					case StretchOption.Null:
						g.DrawImageUnscaled(img,r);
						break;
					case StretchOption.Repeat:
						for(int i=r.Y;i<r.Bottom;i+=img.Height)
							for(int j=r.X;j<r.Right;j+=img.Height)
								g.DrawImage(img,j,i,img.Width,img.Height);
						break;
				}
				g.Restore(state);
			}
			catch(System.Exception ex)
			{
				Log.Record(ex);
			}
		}
		public static Image GetLightImage(Image img)
		{
			return img;
		}
		public static Image GetDarkImage(Image img)
		{
			return img;
		}
	}
	public enum StretchOption
	{
		Null,
		Scaled,
		HStretch,
		VStretch,
		Repeat,
		HRepeat,
		VRepeat
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -