我想知道截取当前屏幕(按下按钮后)并将其保存在画廊上的代码是什么,因为我没有带SD卡的设备。所以我会保存在默认的图库中。谢谢
发布于 2013-03-08 00:26:10
Bitmap bitmap;
View v1 = findViewById(R.id.rlid);// get ur root view id
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);这应该能起到作用。
用于保存
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg")
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();发布于 2013-03-08 00:31:28
View v1 = L1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);要获得完整的源代码,请访问下面的博客
http://amitandroid.blogspot.in/2013/02/android-taking-screen-shots-through-code.html
用于存储位图以查看以下链接
发布于 2017-06-20 06:53:57
这将保存到画廊。该代码还设置了一个图像路径。这对于Intent.SEND_ACTION和电子邮件意图很有用。
String imagePath = null;
Bitmap imageBitmap = screenShot(mAnyView);
if (imageBitmap != null) {
imagePath = MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap, "title", null);
}
public Bitmap screenShot(View view) {
if (view != null) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
return null;
}https://stackoverflow.com/questions/15276346
复制相似问题