zoukankan      html  css  js  c++  java
  • .Net语言 APP开发平台——Smobiler学习日志:快速实现应用中的图片、声音等文件上传功能

    最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便

    样式一

    一、目标样式

    目标样式

    我们要实现上图中的效果,需要如下的操作:

    1.从工具栏上的“Smobiler Components”拖动一个ResourceUploader控件和一个ImageButton控件到窗体界面上

    目标样式

    2.ImageButton的Click事件

    VB:
       Private Sub imageButton1_Click(sender As Object, e As EventArgs)Handles imageButton1.Click
           resourceUploader1.Show()
       End Sub
    C#:
       private void imageButton1_Click(object sender, EventArgs e)
       {
           resourceUploader1.Show();
       }

    3.修改ResourceUploader控件的属性

    a.MaxSelectCount属性

    设置资源单次上传的最大数量,默认设置为“9”,一次最多上传9张图片,如图1;

    b.QualityMode属性

    获取或设置相机组件上传质量的模式,默认设置为“Custom”,即表示压缩上传和原图上传都支持,如图2;

    若将该属性设置为“Compressed”,则表示只能压缩上传;

    若将该属性设置为“Original”,则表示只能原图上传;

    MaxSelectCount属性 QualityMode属性
    图1 图2

    c.Uploading事件

    VB:
       Dim imglist As List(Of String) = New List(Of String)
       Private Sub resourceUploader1_Uploading(sender As Object, e As BarcodeData)Handles resourceUploader1.Uploading
           Try
               If e.IsError = False Then
                   e.SaveFile()
                   imglist.Add(e.ResourceID)
                   getImg() 
               End If
           Catch ex As Exception
               MessageBox.Show(ex.Message)
          End Try 
       End Sub
    C#:
       private List<string> imglist = new List<string>();
       private void resourceUploader1_Uploading(object sender, BinaryData e)
       {
           try
           {
               if (e.IsError == false)
               {
                   e.SaveFile();
                   imglist.Add(e.ResourceID);
                   getImg(); 
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

    注:调用ResourceUploader控件来获取图片

    d.其他代码

    VB:
       Private Sub resourceuploader1_ImageCaptured(sender As Object, e As BarcodeData)Handles resourceuploader1.ImageCaptured
            If imglist.Count > 0 & imglist.Count <= 9 Then
               For i = 0 To imglist.Count Step 1
                   Select Case i
                       Case 1
                           img1.Visible = true
                           btndelimg1.Visible = true
                           img1.ResourceID = imglist(i - 1)
                           img1.Refresh()
                       Case 2
                           img2.Visible = true
                           btndelimg2.Visible = true
                           img2.ResourceID = imglist(i - 1)
                           img2.Refresh()
                       Case 3
                           img3.Visible = true
                           btndelimg3.Visible = true
                           img3.ResourceID = imglist(i - 1)
                           img3.Refresh()
                       Case 4
                           img4.Visible = true
                           btndelimg4.Visible = true
                           img4.ResourceID = imglist(i - 1)
                           img4.Refresh()
                       Case 5
                           img5.Visible = true
                           btndelimg5.Visible = true
                           img5.ResourceID = imglist(i - 1)
                           img5.Refresh()
                       Case 6
                           img6.Visible = true
                           btndelimg6.Visible = true
                           img6.ResourceID = imglist(i - 1)
                           img6.Refresh()
                       Case 7
                           img7.Visible = true
                           btndelimg7.Visible = true
                           img7.ResourceID = imglist(i - 1)
                           img7.Refresh()
                       Case 8
                           img8.Visible = true
                           btndelimg8.Visible = true
                           img8.ResourceID = imglist(i - 1)
                           img8.Refresh()                       
                       Case 9
                           img9.Visible = true
                           btndelimg9.Visible = true
                           img9.ResourceID = imglist(i - 1)
                           img9.Refresh()
                  End Select 
               Next
           End If
       End Sub
    C#:
       private void getImg()
       {
           if (imglist.Count > 0 & imglist.Count <= 9)
           {
               for (int i = 1; i <= imglist.Count; i++)
               {
                   switch (i)
                   {
                       case 1:
                           img1.Visible = true;
                           btndelimg1.Visible = true;
                           img1.ResourceID = imglist[i - 1];
                           img1.Refresh();
                           break;
                       case 2:
                           img2.Visible = true;
                           btndelimg2.Visible = true;
                           img2.ResourceID = imglist[i - 1];
                           img2.Refresh();
                           break;
                       case 3:
                           img3.Visible = true;
                           btndelimg3.Visible = true;
                           img3.ResourceID = imglist[i - 1];
                           img3.Refresh();
                           break;
                       case 4:
                           img4.Visible = true;
                           btndelimg4.Visible = true;
                           img4.ResourceID = imglist[i - 1];
                           img4.Refresh();
                           break;
                       case 5:
                           img5.Visible = true;
                           btndelimg5.Visible = true;
                           img5.ResourceID = imglist[i - 1];
                           img5.Refresh();
                           break;
                       case 6:
                           img6.Visible = true;
                           btndelimg6.Visible = true;
                           img6.ResourceID = imglist[i - 1];
                           img6.Refresh();
                           break;
                       case 7:
                           img7.Visible = true;
                           btndelimg7.Visible = true;
                           img7.ResourceID = imglist[i - 1];
                           img7.Refresh();
                           break;
                       case 8:
                           img8.Visible = true;
                           btndelimg8.Visible = true;
                           img8.ResourceID = imglist[i - 1];
                           img8.Refresh();
                           break;
                       case 9:
                           img9.Visible = true;
                           btndelimg9.Visible = true;
                           img9.ResourceID = imglist[i - 1];
                           img9.Refresh();
                           break;
                   }
               }
           }
       }

    二、手机效果显示

    手机效果显示 手机效果显示 手机效果显示 手机效果显示
  • 相关阅读:
    tf.placeholder函数说明
    网易雷火 游戏研发一面 5.7
    【python3】with的用法
    一分钟理解softmax函数(超简单)
    网易雷火 笔试 4.25
    cun
    HDU-2045-RPG上色(递推)
    HDU-2050-折线分割平面 (递推)
    POJ-2389-Bull Math(高精度乘法)
    HDU-1002-A + B Problem II(高精度加法)
  • 原文地址:https://www.cnblogs.com/amanda112/p/6163813.html
Copyright © 2011-2022 走看看