C#圖片查看器實現(xiàn)方法
更新時間:2018年03月27日 08:48:32 作者:彬菌
本篇文章給大家分享了用C#制作圖片查看器的方法以及先實現(xiàn)代碼,有需要的讀者們參考下。
實現(xiàn)效果:
注意:using system.io; 往Form1上添加控件picturebox,再添加imagelist,并設(shè)置imagelist的imagesize大小
Form1.cs代碼:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace ImageCheck { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int index; private void button1_Click(object sender, EventArgs e) { index--; if (index<0) { MessageBox.Show("去往最后一張圖片"); index = imageList1.Images.Count - 1; } this.pictureBox1.Image = this.imageList1.Images[index]; } private void button2_Click(object sender, EventArgs e) { index++; if (index>imageList1.Images.Count-1) { MessageBox.Show("回到第一張圖片"); index = 0; } this.pictureBox1.Image = this.imageList1.Images[index]; } private void LoadImage() { string rootPath = Application.StartupPath; string filePath = rootPath + @"\image"; DirectoryInfo rootDir = new DirectoryInfo(filePath); FileInfo[] file = rootDir.GetFiles(); for (int i=0;i<=file.Length-1;i++) { Image img = Image.FromFile(file[i].FullName); this.imageList1.Images.Add(img); } } private void Form1_Load(object sender, EventArgs e) { LoadImage(); this.pictureBox1.Image = this.imageList1.Images[index]; } } }
注意:在C#的工作目錄Debug下創(chuàng)建image文件夾,并放置圖片
相關(guān)文章
詳解如何實現(xiàn)C#和Python間實時視頻數(shù)據(jù)交互
我們在做RTSP|RTMP播放的時候,遇到好多開發(fā)者,他們的視覺算法大多運(yùn)行在python下,需要高效率的實現(xiàn)C#和Python的視頻數(shù)據(jù)交互,本文給大家總結(jié)了一些常用的方法,感興趣的小伙伴跟著小編一起來看看吧2024-10-10C#中讓控件全屏顯示的實現(xiàn)代碼(WinForm)
有時候需要讓窗口中某一塊的內(nèi)容全屏顯示,比如視頻播放、地圖等等。經(jīng)過摸索,暫時發(fā)現(xiàn)兩種可行方法,如果有誰知道其他方法,敬請告知2012-04-04c#實現(xiàn)一個超實用的證件照換底色小工具(附源碼)
這篇文章主要給大家介紹了關(guān)于利用c#實現(xiàn)一個超實用的證件照換底色小工具的相關(guān)資料,通過這個小工具大家可以很方便的進(jìn)行底色的切換,不用再因為底色的原因頭疼了,需要的朋友可以參考借鑒,下面來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01