找不到文件路径 - 图片

时间:2015-06-10 14:33:36

标签: c# android ftp xamarin android-resources

我目前正尝试在Android上通过FTP发送图片。 我尝试了很多可能的方法来实现这一点,同样的问题仍然存在:我收到错误,告诉路径/目录/文件不存在。

我现在的代码是使用Xamarin的CameraSample并从相机拍摄照片并尝试通过FTP发送。当我尝试这样做时,我收到错误:

  

ENOENT(没有这样的文件或目录)

以下是代码:

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
        base.OnActivityResult(requestCode, resultCode, data);

        // make it available in the gallery
        Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
        Uri contentUri = Uri.FromFile(_file);
        System.Console.WriteLine (contentUri.ToString ());
        mediaScanIntent.SetData(contentUri);
        SendBroadcast(mediaScanIntent);

        // display in ImageView. We will resize the bitmap to fit the display
        // Loading the full sized image will consume to much memory 
        // and cause the application to crash.
        int height = _imageView.Height;
        int width = Resources.DisplayMetrics.WidthPixels;
        using (Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height))
        {
            _imageView.RecycleBitmap ();
            _imageView.SetImageBitmap(bitmap);
        }

        Thread t = new Thread ( () => UploadToFTP(contentUri.ToString()));
        t.Start ();
    }

    private void UploadToFTP(String uri){
        SimpleFTP ftp = new SimpleFTP ();
        ftp.Connect("xxx.xxxxx.xxx", 21, "xxxxxxx", "xxxxxxxx");
        ftp.Stor (new File(uri));
        ftp.Disconnect();
    }

有没有人有想法发生了什么?我已尝试过资产/可绘制/文件等,但没有任何作用。 可以在ImageView上看到图像。

控制台上打印的路径是:

  

文件:///storage/sdcard0/Pictures/CameraAppDemo/myPhoto_64ee3f​​ec-08af-4bde-9214-62892b6d9f72.jpg

由于

修改 我想通了......问题是使用contentUri.ToString()代替contentUri.Path,后者的结果是正确的,没有" file://&#34 ; 部分,所以它应该是这样的:

  

/storage/sdcard0/Pictures/CameraAppDemo/myPhoto_64ee3f​​ec-08af-4bde-9214-62892b6d9f72.jpg

0 个答案:

没有答案