110,533
社区成员
发帖
与我相关
我的任务
分享
// 得到要刷新的Rectangle
RectangleF dstRect = pe.ClipRectangle;
// 计算出对应的在图像上要显示的部分
RectangleF sourceRect = m_transform.TransformScreenToImage(dstRect);
if (this.Image != null)
{
// 画出图像
pe.Graphics.DrawImage(this.Image, dstRect, sourceRect, GraphicsUnit.Pixel);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication155
{
public partial class Form1 : Form
{
PictureBox PBView = new PictureBox();
PictureBox PBZoom = new PictureBox();
public Form1()
{
InitializeComponent();
PBView.Image = new Bitmap(@"C:\WINDOWS\Web\Wallpaper\Bliss.bmp");
PBView.Parent = this;
PBView.SizeMode = PictureBoxSizeMode.StretchImage;
PBView.Size = new Size(100, 100);
PBView.MouseMove += new MouseEventHandler(PBView_MouseMove);
PBZoom.Parent = this;
PBZoom.Location = new Point(0, 100);
PBZoom.Size = new Size(500, 500);
this.Size = new Size(600, 600);
}
void PBView_MouseMove(object sender, MouseEventArgs e)
{
Bitmap Bmp = new Bitmap(500, 500);
using (Graphics G = Graphics.FromImage(Bmp))
G.DrawImage(PBView.Image, new Rectangle(new Point(0, 0), Bmp.Size),
new Rectangle(new Point(e.X *PBView.Image.Width / PBView.ClientRectangle.Width,
e.Y * PBView.Image.Height / PBView.ClientRectangle.Height),
new Size(100,100)),
GraphicsUnit.Pixel);
PBZoom.Image = Bmp;
}
}
}