哪何把pictureBox1中的一部分图片拷贝到pictureBox2中去?
哪何把pictureBox1中的一部分图片拷贝到pictureBox2中去?? --------------------编程问答-------------------- Graphics取得picture1图片定义一个Rectangle,表示一部分。
Graphics.SetClip获取剪切部分
DrawImage到picture2 --------------------编程问答-------------------- PictureBox有Image属性,表示一个图片实例,可以使用Graphics对象将图像的指定区域绘制到特定区域。 --------------------编程问答-------------------- PictureBox1.DrawToBitmap(bitmap, New Rectangle(0, 0, 20, 20))
PictureBox2.image=bitmap --------------------编程问答--------------------
这个方法也可以。
另外也有个方法是一样的道理 :
你可以先定义你要拷贝的图片的区域:Rectangle rect=New Rectangle(0, 0, 20, 20);
然后用bitmap.clone();方法就可以了。也就是你的new bitmap(pictureBox1).clone(rect); --------------------编程问答-------------------- 好像可以将第一次加载进图片的时候就就将路径记下,在2中直接加载就行了! --------------------编程问答-------------------- PictureBox1.DrawToBitmap(bitmap, New Rectangle(0, 0, 20, 20))
PictureBox2.image=bitmap
这个怎么PictureBox2里面没东西,是空白的? --------------------编程问答-------------------- 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
{
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中显示,要怎么写呀? --------------------编程问答-------------------- --------------------编程问答-------------------- 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);
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 { }
}
}
}
--------------------编程问答-------------------- 我需要一个dll函数,让vb6来调用,就是:我有一个picturebox2,里面的图片要用滚动条来显示全部,里面有很多的image小控件(也是图片),要将image里面的图连同picture2中的图一起保存。谁会做?我的qq:691868555,价格300元. --------------------编程问答-------------------- 我需要一个dll函数,让vb6来调用,就是:我有一个picturebox2,里面的图片要用滚动条来显示全部,里面有很多的image小控件(也是图片),要将image里面的图连同picture2中的图一起保存。谁会做?我的qq:691868555,价格300元
补充:.NET技术 , C#