文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>指正源文件并把它转成二进制然后转换成图片进行保存至指定位置

指正源文件并把它转成二进制然后转换成图片进行保存至指定位置

时间:2010-08-31  来源:裴鹏

  //指定源文件夹
        string[] dirs = System.IO.Directory.GetDirectories("E:\\AutoSite\\img\\");
        foreach (string dir in dirs)
        {
            string fileName = dir.Substring(dir.LastIndexOf("\\") + 1); //获取文件夹名
            string[] files = System.IO.Directory.GetFiles(dir + "\\");    //子文件夹

            foreach (string file in files)
            {
                //转换成二进制
                FileInfo f = new FileInfo(file);
                int FileLen = int.Parse(f.Length.ToString());
                Byte[] FileData = new Byte[FileLen];
                FileStream hp = new FileStream(file, FileMode.Open);
                System.IO.Stream sr = System.IO.Stream.Synchronized(hp);
                sr.Read(FileData, 0, FileLen);

                //把二进制转换成图片进行保存至指定位置
                MemoryStream ms = new MemoryStream((Byte[])FileData);//imgname是图片的名字
                Bitmap img = new Bitmap(ms);

                //创建文件夹
                string strAutoID = "file1";  //DDListAutoName.SelectedItem.Value;
                string filepath = "Upimg\\"; //目标地址;

                Random rand = new Random();

                if (Directory.Exists(filepath + strAutoID))
                {
                    string strImg = filepath + strAutoID + "\\" + ((rand.Next(100, 999)) + ".jpg");
                    img.Save(strImg);

                }
                else
                {
                    Directory.CreateDirectory(filepath + strAutoID);
                    string strImg = filepath + strAutoID + "\\" + ((rand.Next(100, 999)) + ".jpg");
                    img.Save(strImg);

                }
            }
        }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载