哪何把pictureBox1中的一部分图片拷贝到pictureBox2中去??
解决方案 »
- 熟悉Entity framework的速来救命!
- ReportViewer问题
- DataGridView里面的字符串长度以及类型处理,搞定就给分
- vs2008操作出现的警告问题。
- 请教一个关于序列化的问题.
- 使用sql数据库简单实例时出现的问题未将对象引用设置到对象的实例
- C#窗体问题,谢谢!
- ★★★★★★★★请问这是什么编码?★★★★★★★★
- OleDbDataAdapter.fill 插入DataTable中并转为Excel 列错位了。
- C#调用dll文件中的构造函数
- 如何去除xml根节点的属性xmlns?
- GridView1.Rows[e.RowIndex].Cells[3].Text.Trim()==""为什么是true
定义一个Rectangle,表示一部分。
Graphics.SetClip获取剪切部分
DrawImage到picture2
PictureBox2.image=bitmap
这个方法也可以。
另外也有个方法是一样的道理 :
你可以先定义你要拷贝的图片的区域:Rectangle rect=New Rectangle(0, 0, 20, 20);
然后用bitmap.clone();方法就可以了。也就是你的new bitmap(pictureBox1).clone(rect);
PictureBox2.image=bitmap这个怎么PictureBox2里面没东西,是空白的?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void 打开oToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
pic1.Image = Image.FromFile(openFileDialog1.FileName);
}
} private void pic1_MouseMove(object sender, MouseEventArgs e)
{
try
{
int x = 50;
pic2.Left = e.X - x;
pic2.Top = e.Y - x;
Bitmap bitmap = new Bitmap(x,x);
Rectangle ret = new Rectangle(e.X - 25, e.Y - 25, x, x);
pic2.Image = bitmap;
pic1.DrawToBitmap(bitmap,ret);
pic2.Image = bitmap; }
catch { }
}
}
}
pic2中是空白的,没有能局部拷贝。想把pic1中的指定区域拷贝到pic2中显示,要怎么写呀?
{
try {
int x = 50;
pic2.Left = e.X - x;
pic2.Top = e.Y - x;
Bitmap bitmap = new Bitmap(x, x);
Rectangle ret = new Rectangle(e.X - 25, e.Y - 25, x, x);
bitmap = Pic1.Image;
Bitmap bp = default(Bitmap);
bp = bitmap.Clone(ret, Imaging.PixelFormat.DontCare);
Pic2.Image = bp;
}
catch {
}
}
不过解决了!using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void 打开oToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
pic1.Image = Image.FromFile(openFileDialog1.FileName);
}
} private void pic1_MouseMove(object sender, MouseEventArgs e)
{
try
{
// if (openFileDialog1.FileName != "")
// {
int x = 80; //放大取景大小
int y = 2; //放大倍数
pic2.Left = e.X - x;
pic2.Top = e.Y - x;
pic2.Width = x * y;
pic2.Height = x * y;
Rectangle sourceRectangle = new Rectangle(e.X-x/y, e.Y - x/y, x, x);
Rectangle destRectangle = new Rectangle(0,0, x*y, x*y);
Graphics g = pic2.CreateGraphics();
g.DrawImage(pic1.Image, destRectangle, sourceRectangle, GraphicsUnit.Pixel);
}
catch { }
}
}
}