我尝试以编程方式截取imageview的屏幕截图!当图像保存到文件夹时,它产生黑色图像!当我试图截取我的整个滚动视图的截图时,我能够截取屏幕截图。请帮忙:
我的代码是:
private void saveop(){
RelativeLayout parent = (RelativeLayout) findViewById(R.id.opimagelayout);// which includes your view or buttons?
Bitmap bitmap = Bitmap.createBitmap(384,
100, Bitmap.Config.ARGB_8888);
Canvas bitmapHolder = new Canvas(bitmap);
parent.draw(bitmapHolder);
try {
final File f = savebitmaps(bitmap,"operator","");
} catch (IOException e) {
e.printStackTrace();
}
}
public static File savebitmaps(Bitmap bmp,String transno, String currentDateandTime) throws IOException {
Bitmap out = BITMAP_RESIZER(bmp, 384,112);
File folder = new File(Environment.getExternalStorageDirectory() + "/MobeeLoad");
File file = new File(folder, transno+".jpg");
FileOutputStream fOut;
try {
fOut = new FileOutputStream(file);
out.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
bmp.recycle();
out.recycle();
} catch (Exception e) {
}
bmp.recycle();
return file;
}
布局xml:
<RelativeLayout
android:id="@+id/opimagelayout"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_below="@+id/date"
android:layout_height="90dp">
<ImageView
android:id="@+id/opimage"
android:layout_width="90dp"
android:src="@drawable/check"
android:layout_centerHorizontal="true"
android:layout_height="90dp" />
</RelativeLayout>