-1
在這裏,我想截圖,也保存到SD卡,但我保存失敗。請幫幫我。要採取截圖並將其保存到SD卡
public void onClick(View OnclickView) {
boolean success = false;
view = OnclickView.getRootView();
view.setDrawingCacheEnabled(true);
bitmap = view.getDrawingCache();
ScreenShotHold.setImageBitmap(bitmap);
bitmap.compress(Bitmap.CompressFormat.PNG, 60, bytearrayoutputstream);
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, "test.png");
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
Toast.makeText(getApplicationContext(), "bitmap " + bitmap, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "outstream " + outStream, Toast.LENGTH_SHORT).show();
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (success == true) {
Toast.makeText(getApplicationContext(), "Saved", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_SHORT).show();
}
}
在這裏我得到失敗的結果,但我得到了截圖。
我的理解是,你必須有清單中設置權限SD卡 – ziondreamt
亞我已經做到了在第一,但我沒有得到。 – Kogile
您正在試圖用這個Android版本 – Piyush