小怪兽爱吃肉
我写了一个关于它的演示。我将图片放在资源文件夹中,然后将其读取为位图 btnSelectImage = (Button)FindViewById(Resource.Id.btnSelectImage); Bitmap bitmap = BitmapFactory.DecodeResource(this.ApplicationContext.Resources , Resource.Drawable.splashlogo); btnSelectImage.Click += (o, e) => { saveImageToGally(bitmap, this); };然后将其发送到图库中的特定相册。有代码。public void saveImageToGally(Bitmap finalBitmap,Context context) { //create a directory called MyCamera string root = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim).ToString() + "/MyCamera/"; //create the Directory System.IO.Directory.CreateDirectory(root); File myDir = new File(root); myDir.Mkdir(); //Image name string fname = "Image-" + "Image1" + ".png"; File file = new File(myDir, fname); Log.Error("FilePath", file.AbsolutePath); if (file.Exists()) file.Delete(); Log.Error("FilePath", root + fname); //total path string path = root + fname; try { var fs = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate); if (fs != null) { finalBitmap.Compress(Bitmap.CompressFormat.Png, 90, fs); fs.Close(); } } catch (Exception e) { e.PrintStackTrace(); } MediaScannerConnection.ScanFile(context, new string[] { file.Path }, new string[] { "image/jpeg" }, null); }请不要忘记添加以下权限。<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />