首先在pictureBox上画了个图,但如何引用这个图?
即把我画的这个图变成pictureBox的Image属性,因为我想接着对它进行放大,但放大时需要用到pictureBox1.Image!望高手指教!!谢谢

解决方案 »

  1.   

    怎么画的?用GDI+?
    Graphics g = pictureBox.CreateGraphics();
      

  2.   

    是这样的:
    System.Drawing.Graphics  mydraw;
    mydraw=pictureBox1.CreateGraphics();
    mydraw.DrawLine(......)
    绘出了一个分形图
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 实验程序
    {
        
        public partial class Form1 : Form
        {
            Image pbImg = null;
            Rectangle rect = new Rectangle(50, 50, 100, 100);
            public Form1()
            {
                InitializeComponent();
                pbImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                DrawSomething(Graphics.FromImage(pbImg), rect);
                pictureBox1.Image = pbImg;
            }        private void DrawSomething(Graphics g,Rectangle rec)
            {
                g.Clear(pictureBox1.BackColor);
                g.DrawRectangle(new Pen(Color.Red, 1), rec);
            }        private void btn_ZoomIn_Click(object sender, EventArgs e)
            {
                int x = rect.Left * 2 + (1 - 2) * pictureBox1.Width / 2;
                int y = rect.Top * 2 + (1 - 2) * pictureBox1.Height / 2;
                int w = rect.Width * 2;
                int h = rect.Height * 2;
                rect = new Rectangle(x, y, w, h);
                DrawSomething(Graphics.FromImage(pbImg), rect);
                pictureBox1.Image = pbImg;
            }        private void btn_ZoomOut_Click(object sender, EventArgs e)
            {
                int x = (int)(rect.Left * 0.5 + (1 - 0.5) * pictureBox1.Width / 2);
                int y = (int)(rect.Top * 0.5 + (1 - 0.5) * pictureBox1.Height / 2);
                int w = (int)(rect.Width * 0.5);
                int h = (int)(rect.Height * 0.5);
                rect = new Rectangle(x, y, w, h);
                DrawSomething(Graphics.FromImage(pbImg), rect);
                pictureBox1.Image = pbImg;
            }
        }}