我的WinForm里有一个pictureBox1控件,有一张图片c:\test.jpg
我想载入图片到pictureBox1控件后,能在图片上有一个可以在pictureBox1控件里移动的矩形框,
在矩形框里显示的正常的图像,而未在矩形框内显示的就变暗一点。就像photoshop里的剪裁选择的效果,只不过我不要求矩形框能缩变,固定大小就行了。哪位高手能解决呢,谢谢。

解决方案 »

  1.   

    给你个方案吧,你可以创建一张同样大小的灰度图片,然后进行ALPHA混合,就可以得到较暗的图,接下来再把要变亮的部份贴上去,
    2,可以直接做一个同样大小的点网图
      

  2.   

    tslkfyh(TSL) ( ) 信誉:100  2005-08-03 13:10:00  得分: 0  
     
     
       给你个方案吧,你可以创建一张同样大小的灰度图片,然后进行ALPHA混合,就可以得到较暗的图,接下来再把要变亮的部份贴上去,
    2,可以直接做一个同样大小的点网图
      
     
    就这样,移动矩形框,就是贴不同的块上去。
      

  3.   

    用GDI+把巨型框画出来,其实就是判断坐标的问题,想想是不是
      

  4.   

    给一个思路, 定义一个Reign, 中空,象回字, Regin 区域是Alpha 进行透明处理就行了,改变中心的矩形框即是重建一个Regin
      

  5.   


    using System;
    using System.Drawing;
    using System.ComponentModel;
    using System.Windows.Forms;
    namespace ViewPicture
    {
    public class frmViewImg : System.Windows.Forms.Form
    {

    private System.ComponentModel.Container components = null;                  private System.Windows.Forms.PictureBox pictureBox1;
    private bool mouseDown = false;
    private System.Windows.Forms.Panel panel2;
    private System.Windows.Forms.PictureBox pictureBox2;
    private Point point ; public frmViewImg()
    {
    InitializeComponent();
    } protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmViewImg));
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    this.panel2 = new System.Windows.Forms.Panel();
    this.pictureBox2 = new System.Windows.Forms.PictureBox();
    this.panel2.SuspendLayout();
    this.SuspendLayout();
    // 
    // pictureBox1
    // 
    this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
    this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;
    this.pictureBox1.Location = new System.Drawing.Point(232, 152);
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(152, 144);
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;
    this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
    this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
    this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
    // 
    // panel2
    // 
    this.panel2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel2.BackgroundImage")));
    this.panel2.Controls.Add(this.pictureBox1);
    this.panel2.Controls.Add(this.pictureBox2);
    this.panel2.Location = new System.Drawing.Point(24, 64);
    this.panel2.Name = "panel2";
    this.panel2.Size = new System.Drawing.Size(560, 472);
    this.panel2.TabIndex = 3;
    // 
    // pictureBox2
    // 
    this.pictureBox2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox2.BackgroundImage")));
    this.pictureBox2.Location = new System.Drawing.Point(0, 0);
    this.pictureBox2.Name = "pictureBox2";
    this.pictureBox2.Size = new System.Drawing.Size(560, 472);
    this.pictureBox2.TabIndex = 0;
    this.pictureBox2.TabStop = false;
    // 
    // frmViewImg
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
    this.ClientSize = new System.Drawing.Size(632, 581);
    this.Controls.Add(this.panel2);
    this.Name = "frmViewImg";
    this.Text = "?示?片";
    this.panel2.ResumeLayout(false);
    this.ResumeLayout(false); }
    [STAThread]
    static void Main() 
    {
    Application.Run(new frmViewImg());
    } private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Left)
    {
    mouseDown = true;
    point = new Point(e.X, e.Y);
    }
    } private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    mouseDown = false;
    } private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(mouseDown)
    {
    pictureBox1.Location = new Point(pictureBox1.Left + e.X - point.X, pictureBox1.Top + e.Y - point.Y); this.pictureBox2.Refresh();
    this.pictureBox1.Refresh();
    }
    }
    }
    }希望有点用处!
      

  6.   

    编译前请重新panel2 和pictureBox2的背景图片。