Java 每次拍摄屏幕截图以显示图像到图像查看器应用程序
我有截图按钮,当我拍摄截图时,图像应该存储在sd卡中,当我去看画廊时,他们会显示图像 但是,我想在每次拍摄截图时,在图像查看器应用程序中显示 我的代码在这里:Java 每次拍摄屏幕截图以显示图像到图像查看器应用程序,java,android,Java,Android,我有截图按钮,当我拍摄截图时,图像应该存储在sd卡中,当我去看画廊时,他们会显示图像 但是,我想在每次拍摄截图时,在图像查看器应用程序中显示 我的代码在这里: public class MainActivity extends Activity { Button captureImage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceStat
public class MainActivity extends Activity {
Button captureImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
captureImage = (Button)findViewById(R.id.captureImage);
captureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
}
private void saveBitmap(Bitmap bitmap) {
// TODO Auto-generated method stub
File imagePath = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/"+"MyProfile.JPEG");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(imagePath)));
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(), "Screen short saved", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "something wrong", Toast.LENGTH_SHORT).show();
}
}
private Bitmap takeScreenshot() {
// TODO Auto-generated method stub
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
});
}
清单
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
屏幕截图:
public class MainActivity extends Activity {
Button captureImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
captureImage = (Button)findViewById(R.id.captureImage);
captureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
}
private void saveBitmap(Bitmap bitmap) {
// TODO Auto-generated method stub
File imagePath = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/"+"MyProfile.JPEG");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(imagePath)));
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
Toast.makeText(getApplicationContext(), "Screen short saved", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "File not found", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "something wrong", Toast.LENGTH_SHORT).show();
}
}
private Bitmap takeScreenshot() {
// TODO Auto-generated method stub
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
});
}
我需要像这样出去
我不明白你需要什么。是否要在ImageView上显示结果?您可以这样做:
imageView.setImageBitmap(位图)代码>完美存储并显示在图像到图像视图中。我所需要的意思是,当我缩短屏幕时,我想显示图像查看器。图像查看器-只有默认的移动图像查看器。