图片框
圖 片 框 圖片框 圖片框
1.圖片框
圖片
Image:抽象類,圖像的統稱
Bitmap:具體類,位圖,像素圖
示例:
PictureBox圖片框控件:用于顯示一個圖片
設置縮放模式
顯示圖片
picbox.Image = img;或者加載圖片
picbox.Load("c: \ \example \ \123.jpg");1圖片文件的路徑,用windows路徑(反斜杠)
"c:\\example\\123.jpg""c:/example/123.jpg”不支持
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace WinForm基礎22 {public partial class Form1 : Form{public Form1(){InitializeComponent();Bitmap img = new Bitmap("E:\\cat.png");int w = img.Width;int h = img.Height;pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;pictureBox1.Image = img;}} }2.圖片資源
Bitmap:具體類,位圖,像素圖
圖片的來源:
- 本地文件,如"E:\cat.png"
- 資源文件
- 網絡文件,如http://qq.cn/img/cat.jpg
資源文件:
Properties \ Resources.resx可以添加字符串、位圖、圖標、音頻等類型的資源
添加資源:
1 雙擊Resources.resx,打開資源編輯器
2 添加資源 | 添加現有文件
選擇一張圖片文件
3 修改資源名稱
4 使用資源
在程序打包時,資源數據被打包到EXE程序中
總結
- 上一篇: 高德,微信公众号,企业微信获取定位
- 下一篇: 静态路由 动态路由 默认路由 默认网关