- 需要注意的是,当在工程中导入图片后,可以点击图片右击显示属性,在生成操作中可以设置内容或嵌入资源,这两种设置直接关系到下面取图片的方法,详情请看代码:
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace PictureBoxControlTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click( object sender, EventArgs e)
- {
- //从图片文件载入
- //下面的路径是写死的,可以获取程序运行路径,这样更灵活
- pictureBox1.Image = new Bitmap(@ "/Program Files/PictureBoxControlTest/tinyemulator_content.jpg" );
- }
- private void button2_Click( object sender, EventArgs e)
- {
- //通过imageList控件载入,这种方法的好处是可以设置图片的大小
- imageList1.ImageSize = new Size(92,156);
- pictureBox1.Image = imageList1.Images[0];
- }
- private void button3_Click( object sender, EventArgs e)
- {
- //从程序的资源文件载入.这样做的好处是无需发布图片,已经被整合到程序集中去了.
- Bitmap bmp=new Bitmap (System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream
- ("PictureBoxControlTest.tinyemulator_res.jpg" ));
- pictureBox1.Image =bmp;
- }
- private void menuItem1_Click( object sender, EventArgs e)
- {
- Application.Exit();
- }
- }
- }
PictureBox加载图片的3种方法
最新推荐文章于 2025-02-28 15:42:35 发布