0

I'm taking a screenshot from a layout that have a videoview, I have this code to save it, and to capture it, but when I open it I have a blank image but not an empty the image have 1.5Kb, can you help me?

this is how I capture the screenshot

 public void TakePic(View v){


    buton = AnimationUtils.loadAnimation(this, R.anim.but);
    v.startAnimation(buton);
    if (vid!=null)
    {
        if(vid.getCurrentPosition()!=0)
        {
            popupc = (LinearLayout) findViewById(R.id.guardapic);
            popupc.setVisibility(View.VISIBLE);

            LinearLayout layout = (LinearLayout)findViewById(R.id.videopic);
            layout.setDrawingCacheEnabled(true);
            layout.setDrawingCacheQuality(LinearLayout.DRAWING_CACHE_QUALITY_HIGH);
            layout.buildDrawingCache();
            bitmap = layout.getDrawingCache();
            im=(ImageView)findViewById(R.id.imgdown);
        //  im.setImageResource(R.drawable.play_amarelo);
            im.setImageBitmap(bitmap);

        }
        else
        {

            Toast toast = Toast.makeText(ctx,"Video has stopped...Restart", Toast.LENGTH_SHORT);
            toast.show();
        }

    }
    else
    {
        Toast toast = Toast.makeText(ctx,"Start video first", Toast.LENGTH_SHORT);
        toast.show();
    }
}

this is the code to save it into the sdCard

 public void PicOk(View v){


   String pathpic=null;

    String nomepic=null;

    EditText path= (EditText)findViewById(R.id.picpath);
    EditText pic= (EditText)findViewById(R.id.nomepic);

    pathpic=path.getText().toString();
    nomepic=pic.getText().toString();

    File folder = new File(Environment.getExternalStorageDirectory() + "/"+pathpic);
    boolean success = true;
    if (!folder.exists()) {
        success = folder.mkdir();

    }
    if (!success) {
        Log.d("Lino"," Pasta nao criada");
    } else {
        FileOutputStream ostream;
        try {

            File file =  new File(folder.toString() + "/"+nomepic+ ".png");
            ostream = new FileOutputStream(file);
            bitmap.compress(CompressFormat.PNG, 95, ostream);

            ostream.flush();
            ostream.close();      
            //              ((LinearLayout)findViewById(R.id.VV2)).destroyDrawingCache();
        } catch (FileNotFoundException e) {

            Log.d("Lino","erro"+e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            Log.d("lino","erro  "+e.toString());
            e.printStackTrace();
        }
    }

    popupc = (LinearLayout) findViewById(R.id.guardapic);
    popupc.setVisibility(View.GONE);
    bitmap=null;
    //tira foto
    Toast toast = Toast.makeText(ctx,"pick taked", Toast.LENGTH_SHORT);
    toast.show();

}
Lino
  • 295
  • 1
  • 5
  • 19
  • `layout` only have `Video View` ? If yes, then add a View(A text view with some Text with white color) in your layout file just for testing...then share the results. – Mohsin Naeem Aug 12 '12 at 17:17
  • I did what you said and the text appears in the screenshot but the videoview part still blank – Lino Aug 12 '12 at 17:58

1 Answers1

1

You know the video is actually Combination of Still Images. The moment when you take the picture the cross-ponding frame is blank. That is why screenshot appears to be black/blank.

So with this method you can't take the screen shot of a video. You need to adopt a different approach.

May be it helps you.

Community
  • 1
  • 1
Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
  • So you are saying that I have to implement the FFMPEG in my project and then decode the video and then extract a frame? that's it? – Lino Aug 13 '12 at 00:09
  • yap that's it :) As I think `FFMPEG` have a method to take screen shots. – Mohsin Naeem Aug 13 '12 at 03:07