0

我正在从具有视频视图的布局中截取屏幕截图,我有此代码来保存它并捕获它,但是当我打开它时,我有一个空白图像但不是一个空图像有 1.5Kb,你能帮忙吗我?

这就是我捕获屏幕截图的方式

 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();
    }
}

这是将其保存到 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();

}
4

1 回答 1

1

你知道视频实际上是Combination of Still Images。当你拍照的那一刻,跨池框架是空白的。这就是为什么屏幕截图看起来是黑色/空白的原因。

因此,使用此方法您无法截取视频的屏幕截图。您需要采用不同的方法。

可能对你有帮助

于 2012-08-12T23:30:36.130 回答