关于pictureBox1.Image的问题

yiheyuan_123 2008-06-12 10:56:39
首先在pictureBox上画了个图,但如何引用这个图?
即把我画的这个图变成pictureBox的Image属性,因为我想接着对它进行放大,但放大时需要用到pictureBox1.Image!

望高手指教!!谢谢
...全文
336 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GentleCat 2008-06-12
  • 打赏
  • 举报
回复
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;
}


}

}
yiheyuan_123 2008-06-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ojlovecd 的回复:]
怎么画的?用GDI+?
Graphics g = pictureBox.CreateGraphics();
[/Quote]
是这样的:
System.Drawing.Graphics mydraw;
mydraw=pictureBox1.CreateGraphics();
mydraw.DrawLine(......)
绘出了一个分形图
我姓区不姓区 2008-06-12
  • 打赏
  • 举报
回复
怎么画的?用GDI+?
Graphics g = pictureBox.CreateGraphics();
yiheyuan_123 2008-06-12
  • 打赏
  • 举报
回复
谢谢楼上点拨!!

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧