我有一個imageview在activity_main和其他imageview在content_main,我想合併圖像並截取它的截圖,但它沒有顯示content_main的圖像。以下是它的照片。合併兩個圖像,並採取佈局android的屏幕截圖android
圖片,我想裏面
Image which I want to capture with the photo inside it
正在被捕獲
代碼中activity_main圖像的照片捕捉到
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl_template_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.template.TemplateOne">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_template_one" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2">
<FrameLayout
android:id="@+id/frame_memecontent"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/ec_rltabselected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp" >
<AbsoluteLayout
android:id="@+id/relative1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/ivCardView"
android:layout_width="match_parent"
android:background="@drawable/template_one_original"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:layout_height="match_parent" />
</AbsoluteLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/llBottomLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="0" >
</LinearLayout>
</FrameLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
代碼中content_main
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.pankaj.birthdayinvitationmaker.others.TouchImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_black_add_image"
android:layout_weight="0.95"
android:adjustViewBounds="false"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="100dp"
android:layout_marginRight="80dp"
android:id="@+id/addImageButton" />
</RelativeLayout>
這裏是我曾經圖象捕捉完成的代碼。
View vScreenShot = findViewById(R.id.frame_memecontent);
FrameLayout z = (FrameLayout) findViewById(R.id.frame_memecontent);
if(z!=null) {
int totalHeight = z.getChildAt(0).getHeight();
int totalWidth = z.getChildAt(0).getWidth();
vScreenShot.layout(0, 0, totalWidth, totalHeight);
}
vScreenShot.buildDrawingCache(true);
//create bitmap and save drawing cache
Bitmap bitmapSetDrawingChache = Bitmap.createBitmap(vScreenShot.getDrawingCache());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmapSetDrawingChache.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
// saving in sdcard
File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "Birthday Invitation Maker" + File.separator);
if(!file.exists())
file.mkdirs();
String imageName = "Image-" + DateFormat.getDateTimeInstance().format(new Date()) + ".jpg";
File f = new File(file,imageName);
try {
FileOutputStream fileOutputStream = new FileOutputStream(f);
fileOutputStream.write(byteArrayOutputStream.toByteArray());
fileOutputStream.close();
Toast.makeText(TemplateOne.this, "Image Saved",Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
歡迎任何建議/意見。提前致謝。
截圖上傳您的圖像捕捉 –