喜气羊羊

羊羊其实是条鱼|每天学习一点点|每天进步一点点

  PHP博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  68 随笔 :: 0 文章 :: 63 评论 :: 0 Trackbacks
Bitmap bmp = new Bitmap(34372601, PixelFormat.Format32bppPArgb);
            bmp.SetResolution(
300300);

            ImageFormat yy 
= bmp.RawFormat;

            Graphics g 
= Graphics.FromImage(bmp);

            

            Image img 
= new Bitmap("bg.jpg");

            g.DrawImage(img, 
new Point(050));

            Image t 
= new Bitmap("t.jpg");

            g.DrawImage(t, 
new Rectangle(50060010001000));

            Image png 
= new Bitmap("png.png");


            ImageAttributes imga 
= new ImageAttributes();
            ColorMap map 
= new ColorMap();
            map.OldColor 
= Color.FromArgb(25502550);
            map.NewColor 
= Color.FromArgb(0000);
            ColorMap[] maps 
= { map };

            imga.SetRemapTable(maps, ColorAdjustType.Bitmap);

            
/*
            float[][] Matrix = 
            {
                new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
                new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
                new float[] {0,0f, 0.0f, 0.0f, 0.3f, 0.0f},
                new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
            };/*

             * 
*/

            
float[][] Matrix = { 
               
new float[] {1.0f,  0.0f,  0.0f,  0.0f0.0f},
               
new float[] {0.0f,  1.0f,  0.0f,  0.0f0.0f},
               
new float[] {0.0f,  0.0f,  1.0f,  0.0f0.0f},
               
new float[] {0.0f,  0.0f,  0.0f,  0.3f0.0f},
               
new float[] {0.0f,  0.0f,  0.0f,  0.0f1.0f}
            };

            ColorMatrix ma 
= new ColorMatrix(Matrix);
            imga.SetColorMatrix(ma, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            g.DrawImage(png, 
new Rectangle(600700200200), 00200200, GraphicsUnit.Pixel, imga);

            ImageFormat xx 
= bmp.RawFormat;



            bmp.Save(
"rs.jpg", ImageFormat.Jpeg);

            

            bmp.Dispose();
            img.Dispose();
            png.Dispose();
            t.Dispose();

            MessageBox.Show(
"ok");


2
 public partial class Catch : Form
    {
        
#region 用户变量
        
private Point DownPoint = Point.Empty;//记录鼠标按下坐标,用来确定绘图起点
        private bool CatchFinished = false;//用来表示是否截图完成
        private bool CatchStart = false;//表示截图开始
        private Bitmap originBmp;//用来保存原始图像
        private Rectangle CatchRect;//用来保存截图的矩形
        #endregion
        
public Catch()
        {
            InitializeComponent();
        }

        
private void Catch_Load(object sender, EventArgs e)
        {
            
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            
this.UpdateStyles();
            
//以上两句是为了设置控件样式为双缓冲,这可以有效减少图片闪烁的问题,关于这个大家可以自己去搜索下
            originBmp = new Bitmap(this.BackgroundImage);//BackgroundImage为全屏图片,我们另用变量来保存全屏图片
        }

        
private void Catch_MouseClick(object sender, MouseEventArgs e)
        {
            
if (e.Button == MouseButtons.Right)
            {
                
this.DialogResult = DialogResult.OK;
                
this.Close();
            }
        }

        
private void Catch_MouseDown(object sender, MouseEventArgs e)
        {
            
if (e.Button == MouseButtons.Left)
            {
                
if (!CatchStart)
                {
//如果捕捉没有开始
                    CatchStart = true;
                    DownPoint 
= new Point(e.X, e.Y);//保存鼠标按下坐标
                }
            }
        }

        
private void Catch_MouseMove(object sender, MouseEventArgs e)
        {
            
if (CatchStart)
            {
//如果捕捉开始
                Bitmap destBmp = (Bitmap)originBmp.Clone();//新建一个图片对象,并让它与原始图片相同
                Point newPoint = new Point(DownPoint.X, DownPoint.Y);//获取鼠标的坐标
                Graphics g = Graphics.FromImage(destBmp);//在刚才新建的图片上新建一个画板
                Pen p = new Pen(Color.Blue, 1);
                
int width = Math.Abs(e.X - DownPoint.X), height = Math.Abs(e.Y - DownPoint.Y);//获取矩形的长和宽
                if (e.X < DownPoint.X)
                {
                    newPoint.X 
= e.X;
                }
                
if (e.Y < DownPoint.Y)
                {
                    newPoint.Y 
= e.Y;
                }
                CatchRect 
= new Rectangle(newPoint, new Size(width, height));//保存矩形
                g.DrawRectangle(p, CatchRect);//将矩形画在这个画板上
                g.Dispose();//释放目前的这个画板
                p.Dispose();
                Graphics g1 
= this.CreateGraphics();//重新新建一个Graphics类
                
//如果之前那个画板不释放,而直接g=this.CreateGraphics()这样的话无法释放掉第一次创建的g,因为只是把地址转到新的g了.如同string一样
                g1 = this.CreateGraphics();//在整个全屏窗体上新建画板
                g1.DrawImage(destBmp, new Point(00));//将刚才所画的图片画到这个窗体上
                
//这个也可以属于二次缓冲技术,如果直接将矩形画在窗体上,会造成图片抖动并且会有无数个矩形.
                g1.Dispose();
                destBmp.Dispose();
//要及时释放,不然内存将会被大量消耗

            }
        }

        
private void Catch_MouseUp(object sender, MouseEventArgs e)
        {
            
if (e.Button == MouseButtons.Left)
            {
                
if (CatchStart)
                {
                    CatchStart 
= false;
                    CatchFinished 
= true;

                }
            }
        }

        
private void Catch_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            
if (e.Button == MouseButtons.Left && CatchFinished)
            {
                
if (CatchRect.Contains(new Point(e.X, e.Y)))
                {
                    Bitmap CatchedBmp 
= new Bitmap(CatchRect.Width, CatchRect.Height);//新建一个于矩形等大的空白图片
                    Graphics g = Graphics.FromImage(CatchedBmp);
                    g.DrawImage(originBmp, 
new Rectangle(00, CatchRect.Width, CatchRect.Height), CatchRect, GraphicsUnit.Pixel);
                    
//把orginBmp中的指定部分按照指定大小画在画板上
                    Clipboard.SetImage(CatchedBmp);//将图片保存到剪贴板
                    g.Dispose();
                    CatchFinished 
= false;
                    
this.BackgroundImage = originBmp;
                    CatchedBmp.Dispose();
                    
this.DialogResult = DialogResult.OK;
                    
this.Close();
                }
            }
        }


    }

 private void button2_Click(object sender, EventArgs e)
        {
            
this.Hide();//隐藏当前窗体
            Thread.Sleep(50);//让线程睡眠一段时间,窗体消失需要一点时间
            Catch CatchForm = new Catch();
            Bitmap CatchBmp 
= new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);//新建一个和屏幕大小相同的图片         
            Graphics g = Graphics.FromImage(CatchBmp);
            g.CopyFromScreen(
new Point(00), new Point(00), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));//保存全屏图片
            CatchForm.BackgroundImage = CatchBmp;//将Catch窗体的背景设为全屏时的图片
            if (CatchForm.ShowDialog() == DialogResult.OK)
            {
//如果Catch窗体结束,就将剪贴板中的图片放到信息发送框中
                IDataObject iData = Clipboard.GetDataObject();
                DataFormats.Format myFormat 
= DataFormats.GetFormat(DataFormats.Bitmap);
                
if (iData.GetDataPresent(DataFormats.Bitmap))
                {
                    richTextBox1.Paste(myFormat);
                    Clipboard.Clear();
//清除剪贴板中的对象
                }
                
this.Show();//重新显示窗体
            }
        }

3
 Graphics g = this.CreateGraphics();

            Pen p 
= new Pen(Color.Red, 1);

            
for (int i = 0; i < 30; i++)
            {
                g.RotateTransform(i);

                g.DrawLine(p, 
0010000);

                g.ResetTransform();
            }

            
//平移坐标轴
            g.TranslateTransform(100100);
            g.DrawLine(p, 
001000);
            g.ResetTransform();

            
//先平移到指定坐标,然后进行度旋转
            g.TranslateTransform(100200);
            
for (int i = 0; i < 8; i++)
            {
                g.RotateTransform(
45);
                g.DrawLine(p, 
001000);
            }

            g.Dispose();


            Graphics g 
= this.CreateGraphics();
            Rectangle rect 
= new Rectangle(1010500500);
            SolidBrush b1 
= new SolidBrush(Color.Black);
            g.FillRectangle(b1, rect);
            
/*
            g.DrawString("我爱你", new Font("微软雅黑", 90), b1, new PointF(90, 10));

            TextureBrush b2 = new TextureBrush(Image.FromFile("OY1-024.JPG"));
            rect.Location = new Point(100, 100);
            rect.Width = 2000;
            rect.Height = 2000;
            g.FillRectangle(b2, rect);
*/


            rect.Location 
= new Point(400400);
            LinearGradientBrush b3 
= new LinearGradientBrush(rect, Color.BlueViolet, Color.Black, LinearGradientMode.ForwardDiagonal);
            g.FillRectangle(b3, rect);

 Pen p = new Pen(Color.Black, 5);

            Graphics g 
= this.CreateGraphics();

            p.DashStyle 
= DashStyle.Dot;
            g.DrawLine(p, 
101020010);

            p.DashPattern 
= new float[] { 31 };
            g.DrawLine(p, 
102020020);

            p.DashStyle 
= DashStyle.Solid;
            p.EndCap 
= LineCap.ArrowAnchor;
            g.DrawLine(p, 
103020030);

            g.Dispose();
            p.Dispose();

4
Graphics g = e.Graphics;

            Pen p 
= new Pen(Color.Aqua, 2);

            g.DrawLine(p, 
102030400);

            g.DrawRectangle(p, 
1010100100);

            g.DrawRectangle(p, 
3020500600);

            g.DrawEllipse(p, 
5070200600);
5

posted on 2008-09-07 21:44 young40 阅读(376) 评论(0)  编辑 收藏 引用 网摘 所属分类: .Net[C#]

只有注册用户登录后才能发表评论。
网站导航: