0

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();
                 }
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Jelly Bean
  • 137
  • 10

1 Answers1

0

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.

Community
  • 1
  • 1
  • it not working properly.it takes screenout of whole screen.i want to the imageview only. – Jelly Bean Sep 05 '13 at 10:26
  • It is black because it is not rendered in the Android part of the OS, it is rendered in video driver, because of this Android has no info about what is showing. When I had this issue I checked the two values in Developer Options. – Dragos Iordache Sep 05 '13 at 15:03
  • You should find a better option for applying filters to photos, opengl is not optimal in Android since it is highly guarded by Android for security and performance reasons, try finding some C libraries and compiling those in ndk, the performance should be good enough. – Dragos Iordache Sep 05 '13 at 15:10