简体   繁体   中英

how to save the image in sdcard in android

i am working on OpenGl Es in android.given efects on images and when i save the image in sdcard it showing black image.how i solve this problem.

File cacheDir; Toast.makeText(ImageProcessingActivity.this, "Photo", 500).show();

                 Bitmap icon;
                 frame.setDrawingCacheEnabled(true);

                 icon = Bitmap.createBitmap(frame.getDrawingCache());
                 Bitmap bitmap = icon;
                 frame.setDrawingCacheEnabled(false);
                 // File mFile1 = Environment.getExternalStorageDirectory();
                 Date d = new Date();
                 String fileName = d.getTime() + "mg1.jpg";

                 File storagePath = (Environment.getExternalStorageDirectory());
                 File dest = new File(storagePath + "/CityAppImages");

                 if (!dest.exists()) {
                 dest.mkdirs();

                 }

                 File mFile2 = new File(dest, fileName);
                 sdpath = mFile2.getAbsolutePath();

                 Log.d("qqqqqqqqqqqqqqqqqqqqqqq", "zzzzzzzz" + sdpath);
                 try {
                 FileOutputStream outStream;

                 outStream = new FileOutputStream(mFile2);

                 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);

                 outStream.flush();

                 outStream.close();
                 Toast.makeText(ImageProcessingActivity.this, "Photo Saved Sucessfully", 500)
                 .show();
                 image.setImageBitmap(bitmap);
                 } catch (FileNotFoundException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 } catch (IOException e) {

                 // TODO Auto-generated catch block
                 e.printStackTrace();
                 Toast.makeText(ImageProcessingActivity.this, "Photo Not Saved Sucessfully",500).show();
                 }

I had this problem once and it was because getDrawingCache is not what it should be. The problem is not the saving, is the way you do it.

From what I understand you want to capture the screen of your app, but this is very tricky and can cause a lot of problems.

Read this topic, since it helped me a lot when I had this problem. How to programmatically take a screenshot in Android?

Edit: Also, because you are using GLES and then printing the screen you should go to Settings > Developer Options > check Disable Hardware Overlays and Force GPU Rendering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM