0

I am trying to create a directory, and save a bitmap to that directory in Xamarin Android.

I believe the error is because the FileOutPut strea is not a System.IO.Stream but I don't know any alternative.

Error CS1502: The best overloaded method match for 'Android.Graphics.Bitmap.Compress(Android.Graphics.Bitmap.CompressFormat, int, System.IO.Stream)' has some invalid arguments (CS1502) (APPNAME)

        public void createBitmap(View view){
        view.DrawingCacheEnabled = true;
        view.BuildDrawingCache (true);
        Bitmap m_Bitmap = view.GetDrawingCache(true);

        Java.IO.File file = new Java.IO.File (Environment.GetExternalStoragePublicDirectory (Environment.DirectoryPictures), "APPNAME");
        System.Console.WriteLine(System.IO.Directory.CreateDirectory(file.AbsolutePath));

            try{
//              if (!root.Mkdirs()){
//                  System.Console.WriteLine("DIRECTORY NOT CREATED");
//              }else{
//                  root.Mkdirs();
//              }

            //FileOutputStream fos  = new FileOutputStream(file, FileMode.CreateNew);
            FileStream fos = new FileStream(directory, FileMode.CreateNew);

            m_Bitmap.Compress (Bitmap.CompressFormat.Png, 100, fos);

        } catch (Java.IO.FileNotFoundException e) {
            System.Console.WriteLine ("FILENOTFOUND");
        } catch (Java.IO.IOException e) {
            System.Console.WriteLine ("IOEXCEPTION");
        }
    }
Tim
  • 2,027
  • 15
  • 24
Coova
  • 1,818
  • 5
  • 36
  • 63
  • 1
    Maybe FileStream is not an OutputStream when [Bitmap.Compress(...)](http://developer.android.com/reference/android/graphics/Bitmap.html#compress%28android.graphics.Bitmap.CompressFormat,%20int,%20java.io.OutputStream%29) need a java.io.OutputStream. Why don't you use the FileOutputStream instead ? – SkyDream Sep 22 '14 at 15:57
  • 1
    You've got commented-out code that does exactly what @SkyDream said; why aren't you using that instead? – Tim Sep 22 '14 at 16:02
  • If I were to use FileOutputStream = new FileOutputStream(file); the error that I recieve is the “Java.IO.OutputStream” to “System.IO.OutputStream” Error. – Coova Sep 22 '14 at 16:31
  • The only other thing I was able to do was create a string "directory" and use a Filestream, but It says that it cannot find the directory that matches the string. So I am looking to create a directory. – Coova Sep 22 '14 at 16:32
  • Possible dupe of http://stackoverflow.com/questions/9906962/cannot-implicitly-convert-type-system-io-stream-to-java-io-inputstream. – Tim Sep 22 '14 at 17:37
  • Didn't you just ask this question? http://stackoverflow.com/questions/25976002/saving-bitmap-to-file-xamarin-monodroid – matthewrdev Sep 23 '14 at 01:21

0 Answers0