我正在从具有视频视图的布局中截取屏幕截图,我有这个代码来保存它并捕获它,但是当我打开它时我有一个空白图像但不是空的图像有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();
}
答案 0 :(得分:1)
您知道该视频实际上是Combination of Still Images
。拍摄照片时,交叉积水框架是空白的。这就是为什么屏幕截图显示为黑色/空白的原因。
因此,使用此方法无法拍摄视频的屏幕截图。您需要采用不同的方法。
可能是helps你。