C# mono android 图片上传进度条实现

private int _count=0;
private int m_count = 0;
System.IO.FileInfo[] fi = null;
System.IO.DirectoryInfo di = null;
private List<string> list;
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_upfile_Click(object sender, System.EventArgs e)
        {
            _count = 0; m_count = 0; fi = null; di = null; list = new List<string>();
            if (FT)
                UtilityClass.SetMessage("请先确定放行后,再图挡拍照及上传", this);
            if (Environment.ExternalStorageState != Environment.MediaMounted)
                UtilityClass.SetMessage("请插入SD卡", this);         
            Java.IO.File _upfile=UtilityClass.retDirectoryForPictures(ID);
            
            if (_upfile == null || _upfile.ToString().Trim().Length == 0)
            {
                UtilityClass.SetMessage("请进行拍图再上传!", this);
                return; }            
            di = new System.IO.DirectoryInfo(_upfile.ToString().Trim());
            fi = di.GetFiles("*"+@"_"+ID.ToString().Trim()+@".jpeg");
         //和数据库中的图片对比,只上传没有保存的图片,其它则删除
         System.Data.DataTable dt=swe.GetJpeg(ID, 0);
         
         foreach (System.IO.FileInfo _pfile in fi)
         {
             System.Data.DataRow[] rs = dt.Select("jpegName='" + _pfile.Name.ToString().Trim() + @"'");
             if (rs.Length ==0)
             {
                 list.Add(_pfile.Name.ToString().Trim());
             }
         }
    if (list.Count == 0) { UtilityClass.SetMessage("没有图片需要上传", this); return; }
    _count = list.Count;
    xh_pDialog = new ProgressDialog(this);
    xh_pDialog.SetProgressStyle(ProgressDialogStyle.Horizontal);//长方形进度条
    xh_pDialog.SetTitle("提示");
    xh_pDialog.SetMessage("图片正在上传中,请等候……");     
    xh_pDialog.Max = _count;
    xh_pDialog.SetCancelable(true);//按返回键取消
    xh_pDialog.Show();
    System.Threading.Thread thread = null;
    thread = new System.Threading.Thread(new ThreadStart(progress));
    thread.Start(); 
        }
        
/// <summary>
/// 线程上传
/// </summary>
private void progress()
        {
            try
            {
                while (m_count <= _count)
                {
                    xh_pDialog.Progress = m_count++; System.Threading.Thread.Sleep(100);
                    
                    try
                    {   
                   bool ret = swe.UploadJpegFile(BitmapBytes(BitmapHelpers.LoadAndResizeBitmap(di + "/" +list[m_count-1].ToString().Trim(), 800, 600)), ID, list[m_count-1].ToString().Trim());
                        if (!ret)
                        {
                            int q = int.Parse("abc");
                            break;
                        }
                        UtilityClass.DeleteJpeg(ID, list[m_count - 1].ToString().Trim());                     
                    }
                    catch (System.Exception)
                    {                        
                        throw;
                    }                   
                }               
                xh_pDialog.Cancel();
            }
            catch (System.Exception)
            {                
                xh_pDialog.Cancel();
                return;
            }
        } 



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

那小x的传说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值