之前那些操作完成对图片的修改之后,就是要保存图片了。

这里保存用到一个SaveFileDialog控件,可以获取用户选择的保存文件的路径。

 if (pictureBox1.Image.Width > )
{
SaveFileDialog saveImageDialog = new SaveFileDialog();//这里实例化一个SaveFileDialog控件,并设置一些属性
saveImageDialog.Title = "图片保存";
saveImageDialog.Filter = @"jpeg|*.jpg|bmp|*.bmp";
saveImageDialog.FileName = getgv();//获取DataGridView控件的内容作文文件名
if (saveImageDialog.ShowDialog() == DialogResult.OK)//弹出对话框
{
string fileName = saveImageDialog.FileName.ToString();//获取文件路径
if (fileName != "" && fileName != null)
{
string fileExtName = fileName.Substring(fileName.LastIndexOf(".") + ).ToString();//截取文件的后缀名
System.Drawing.Imaging.ImageFormat imgformat = null;
if (fileExtName != "")
{
switch (fileExtName)
{
case "jpg":
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case "bmp":
imgformat = System.Drawing.Imaging.ImageFormat.Bmp;
break;
default:
imgformat = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
}
try
{
//Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//保存之前判断文件夹里的图片数量,如果大于256张就要删除第一张
string dpath = fileName.Substring(, fileName.LastIndexOf("\\"));//去除掉文件名
DirectoryInfo dti = new DirectoryInfo(dpath);//根据路径获取目录对象
FileInfo[] file = dti.GetFiles();//获取当前目录的文件列表
if (file.Count() >= )
{
int a = (file.Count()-);
for (int i = ; i <= a; i++)
{
file[i].Delete();
}
}
pictureBox1.Image.Save(fileName, imgformat);//保存文件
MessageBox.Show("保存成功", "提示");
//pictureBox1.Image.Save(saveImageDialog.FileName);
fName = fileName;
}
catch (Exception ex)
{
MessageBox.Show("保存异常 " + ex.Message, "提示");
}
}
}
}
xulielv(fName);//在listview中显示图片 }
}
catch
{ }
 getgv

/// <summary>
/// 获取dataGridView注释作为图片名
/// </summary>
/// <returns></returns>
private string getgv()
{
string txt = "";
try
{
txt += DateTime.Now.ToString("yyyy年MM月dd日HH.mm.ss");
for (int i = ; i < ; i++)
{
txt += ",";
txt += dataGridView1.Rows[].Cells[i].Value.ToString();
}
}
catch(Exception ex)
{
MessageBox.Show("注释内容不符合命名规则 "+ex.Message);
}
return txt;
}

获取dataGridView注释作为图片名

/// <summary>
/// 生成序列中的图片
/// </summary>
private void xulielv(string path)
{
try
{
if (path != "")
{
imageList1.Images.Clear();
string dpath = path.Substring(, path.LastIndexOf("\\"));//去除掉文件名
DirectoryInfo TheFolder = new DirectoryInfo(dpath);//文件路径
List<string> tifNames = new List<string>();
for (int i = ; i < TheFolder.GetFiles().Length; i++)//遍历文件夹
{
if (TheFolder.GetFiles()[i].Length > && TheFolder.GetFiles()[i].Extension == ".jpg" || TheFolder.GetFiles()[i].Extension == ".png")//或者jpg,png 文件大小要大于0且是图片文件
{
Image image = Image.FromFile(TheFolder.GetFiles()[i].DirectoryName + "\\" + TheFolder.GetFiles()[i].Name); //获取文件
tifNames.Add(TheFolder.GetFiles()[i].Name);//添加文件名
imageList1.Images.Add(image);//添加图片
//image.Dispose();
} }
//初始化设置
this.listView1.Items.Clear();
//this.listView1.View = View.LargeIcon;
this.listView1.View = View.Tile;
this.listView1.LargeImageList = this.imageList1;
//开始绑定
this.listView1.BeginUpdate();
for (int i = ; i < tifNames.Count; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
lvi.Text = tifNames[i];
this.listView1.Items.Add(lvi);
}
this.listView1.EndUpdate();
}
else
{
MessageBox.Show("未提供有效路径");
}
}
catch(Exception ex)
{
MessageBox.Show("生成序列失败 "+ex.Message);
} }

xulielv

这个获取图片放入到listview方法,如果图片过大有很多的话,容易造成内存不足而报错的问题。

撤回

 if (bitlist.Count == )//判断供撤回的集合中是否有数据
{
return;
}
for (int i = ; i < bitlist.Count; i++)
{
if (i == bitlist.Count-)
{
if (i == )//如果已经是最后一张,清空picturebox内的图片
{
this.pictureBox1.Image = null;
this.pictureBox1.Refresh();
txt_tjsz.Visible = false;
txt_tjsz.Text = "";
txt_tjwz.Visible = false;
txt_tjwz.Text = "";
return;
}
pic = bitlist[i - ];//绘制图片时的图片对象
this.pictureBox1.Image = pic;//控件显示的图片
this.pictureBox1.Refresh();
bitlist.Remove(bitlist[i]);//从集合中除去撤回的图片
}
}

这里要注意,放入集合中的图片一定要是修改完成以后获取的图片对象,不能是一直在被修改的图片,否则在集合中的图片也是被修改的。

winfrom保存图片,将文件夹中图片放入listview,与撤回操作的更多相关文章

  1. Python--将文件夹中图片按照横屏竖屏进行分类

    搬运链接:https://www.jianshu.com/p/c8be54282e77 """ 可以遍历输入的路径的指定后缀的文件,主要是用来筛选图片,将图片分成 横屏, ...

  2. 有些其他程序设置为从 Outlook 下载并删除邮件。为防止发生此意外情况,我们将这些邮件放入一个特殊的 POP 文件夹中

    最近使用FOXMAIL接收MSN邮件时,发现有一些邮件收取不到,进到WEB页面,页面下方提示“你的邮件位于 POP 文件夹中!有些其他程序设置为从 Outlook 下载并删除邮件.为防止发生此意外情况 ...

  3. 从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法

    原文:从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法 主程序 为 Main_Test.exe 被加载的DLL 为 Load_Test.dll  此DLL 中 有一个 文件夹Re ...

  4. webpack 打包出多个HTML文件,多个js文件,图片文件放置到指定文件夹中

    一.webpack.config.js简单代码 const HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { ...

  5. 【C#操作Excel】同名Excel放入同一文件夹中,然后合并为同一个Excel文件

    近期有对Excel操作的需求,由于都是重复劳动,故分享代码如下,本人也是技术菜鸟没有考虑性能,如果有大牛能够指教就再好不过了 事先电脑中需要安装Excel,然后Vs中引用Microsoft.Offic ...

  6. 使用c#将多个文件放入文件夹中,并压缩下载

    ZipClass.cs  这个是一个压缩文件的类,可直接复制使用,使用到的命名空间是 using System.IO;using ICSharpCode.SharpZipLib;using ICSha ...

  7. python 将指定文件夹中的指定文件放入指定文件夹中

    import os import shutil import re #获取指定文件中文件名 def get_filename(filetype): name =[] final_name_list = ...

  8. C++获取文件夹中所有文件

    获取文件夹中的文件,用到过很多次,每次用的时候都要去查下,很烦,所以想自己写下,当然,借鉴了很多其他大佬的博客 主要实现的函数,如下: void getFiles( string path, vect ...

  9. 用Python批量裁取图,来获取文件夹中所有图片名

    批量截图(截取正方形图,哪个边短就用哪个边作为标准来截取) 功能是裁取图片中红色框的部分. 代码为: import sys from tkinter.tix import Tk from PIL im ...

随机推荐

  1. 561. 数组拆分 I

    题目 python class Solution: def arrayPairSum(self, nums): """ :type nums: List[int] :rt ...

  2. https 请求的端口是443 注意

    注意: 这里录制https的请求 端口号一定是443 才可以抓取到!!!!!! (进坑多次)

  3. Java 判断某一天是这一年的第几天

    package Day8_06; import java.util.*; public class ClassTest { public static void main(String[] args) ...

  4. mysql索引之一:索引基础(B-Tree索引、哈希索引、聚簇索引、全文(Full-text)索引区别)(唯一索引、最左前缀索引、前缀索引、多列索引)

    没有索引时mysql是如何查询到数据的 索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储10 ...

  5. Java-Runoob-高级课程:Java 集合框架

    ylbtech-Java-Runoob-高级课程:Java 集合框架 1.返回顶部 1. Java 集合框架 早在 Java 2 中之前,Java 就提供了特设类.比如:Dictionary, Vec ...

  6. Spark-1.5.2安装--Standalone和Yarn

    Spark Standalone 1.下载scala-2.10.6包解压到指定目录,添加环境变量 #SCALA VARIABLES START export SCALA_HOME=/usr/local ...

  7. c++ 双向链表操作总结

    第一.包含DoubleLinkNode 模板类和DoubleLinkList 模板类 #pragma once #include<iostream> using namespace std ...

  8. linux rar安装

    1.wget http://www.rarsoft.com/rar_CN/rarlinux-3.9.3.tar.gz 2.tar 3.make && make install; 4.需 ...

  9. TCP超时与重传机制

    TCP超时与重传机制    TCP协议是一种面向连接的可靠的传输层协议,它保证了数据的可靠传输,对于一些出错,超时丢包等问题TCP设计的超时与重传机制.其基本原理:在发送一个数据之后,就开启一个定时器 ...

  10. delphi BLE 学习

    TBluetoothLE 控件 TBluetoothLE.FManager: TBluetoothLEManager; class constructor TBluetoothLEManager.Cr ...