这里我试图截取屏幕并保存到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();
}
}
我在这里收到失败的结果,但我正在截图。
答案 0 :(得分:1)
你可以试试这个
Bitmap screenshotedBitmap = yourBitmap;
String lastInsertedPath = MediaStore.Images.Media.insertImage(getContentResolver(), screenshotedBitmap, "myImage", "modified image");
答案 1 :(得分:1)
DECLARE @query varchar(max),
@col varchar(250) = 'd1,d2,d3'
Set @query = 'INSERT INTO [dbo].[MYTABLE](
'+@col+'
)
SELECT ''~N'' AS ['+@col+']'
print @query