基本信息
源码名称:C# FTP UploadImage
源码大小:0.06M
文件格式:.rar
开发语言:C#
更新时间:2016-05-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

開啟圖片並上傳到ftp

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace UploadImage
{
    public partial class Form1 : Form
    {


        public Form1()
        {
            InitializeComponent();            
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            Stream myStream;
            
            OpenFileDialog ofdPic = new OpenFileDialog();
            //取得或設定目前的檔名擴展名,以決定出現在對話方塊中[檔案類型] 的選項。
            ofdPic.Filter = "JPG(*.JPG;*.JPEG);PNG文件(*.PNG)|*.jpg;*.jpeg;*.png";
            //取得或設定檔案對話方塊中目前所選取之篩選條件的索引
            ofdPic.FilterIndex = 1;
            //關閉對話框,還原當前的目錄
            ofdPic.RestoreDirectory = true;
            //取得或設定含有檔案對話方塊中所選文件的名稱。
            ofdPic.FileName = "";
            //允許選取多檔案
            ofdPic.Multiselect = true;

            if (ofdPic.ShowDialog() == DialogResult.OK)
            {
                //得到文件名及路徑
                string sPicPaht = ofdPic.FileName.ToString();

                //FileInfo:提供建立、複製、刪除、移動和開啟檔案的執行個體 (Instance) 方法
                FileInfo fiPicInfo = new FileInfo(sPicPaht);
                //Length:取得目前檔案的大小。以字節為單位
                long lPicLong = fiPicInfo.Length / 1024;
                //得到文名
                string sPicName = fiPicInfo.Name;
                //取得父目錄
                string sPicDirectory = fiPicInfo.Directory.ToString();
                //DirectoryName :取得表示目錄完整路徑。
                string sPicDirectoryPath = fiPicInfo.DirectoryName;
                

                //封裝GDI 點陣圖像,是用來處理像素資料所定義影像的物件。
                //Bitmap類:封裝GDI 點陣圖,這個點陣圖是由圖形影像的像素資料及其屬性所組成。Bitmap 是用來處理像素資料所定義影像的物件。
                Bitmap bmPic = new Bitmap(sPicPaht);

                //如果文件大於500KB,警告
                if (lPicLong > 500)
                {
                    MessageBox.Show("此文件大小為" lPicLong "K;已超過最大限制的500K範圍!");
                }
                else
                {
                    Point ptLoction = new Point(bmPic.Size);
                    if (ptLoction.X > pcbPic.Size.Width || ptLoction.Y > pcbPic.Size.Height)
                    {
                        //pcbPic.Dock = DockStyle.Fill; // 圖像框的停靠方式

                        pcbPic.SizeMode = PictureBoxSizeMode.Zoom; // 圖像充滿圖像框,並且圖像維持比例
                    }
                    else
                    {
                        pcbPic.SizeMode = PictureBoxSizeMode.CenterImage; // 圖像在圖像框置中
                    }
                }

                pcbPic.LoadAsync(sPicPaht); // LoadAsync:非同步載入圖像

                labNameValue.Text = sPicName; // 顯示圖像名 labNameValue:label控件
                labLengthValue.Text = lPicLong.ToString() " KB"; // 顯示圖像大小  labLengthValue:label控件
                labSizeValue.Text = bmPic.Size.Width.ToString() "×" bmPic.Size.Height.ToString(); // 顯示圖像尺寸 labSizeValue:label控件

                string str = System.Windows.Forms.Application.StartupPath;
                bmPic.Save(string.Concat(str "\\", labNameValue.Text), ImageFormat.Jpeg); // 單檔存檔

                #region 顯示在檔名在ListBox, 並多檔存檔
                if ((myStream = ofdPic.OpenFile()) != null)
                {
                    // Insert code to read the stream here.
                    foreach (string strFilename in ofdPic.FileNames)
                    {
                        listBox1.Items.Add(strFilename);
                        //bmPic.Save(string.Concat(str "\\", Path.GetFileName(strFilename)), ImageFormat.Jpeg);
                    }
                    myStream.Close();
                } 
                #endregion
            }
        }