0
我似乎無法將佈局及其視圖組件保存爲位圖。保存包含視圖的佈局的位圖
我期待實現類似這些例子,Create image from view/screen in Android東西, Convert frame layout into image and save it
我遇到的問題是關於像GetDrawingCache()方法,並DrawingCacheEnabled()。 看起來好像我不能在佈局上調用它們。
下面是錯誤
錯誤CS0201:可以作爲一個聲明(CS0201)(APPNAME)
只有分配,調用,遞增,遞減,在等待着,新的對象表達錯誤CS1501:沒有重載方法 'GetDrawingCache' 取0參數(CS1501)(APPNAME)
我目前編碼MonoDroid的/ Xamarin。所以這些方法看起來有點不同,但也許有人可以提供一些見解。
ImageActivity
在這裏,我以編程方式將意見進行佈局。
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
image = new ImageView (this);
//image = FindViewById<ImageView> (Resource.Id.imageView1);
//this.image.SetScaleType (ImageView.ScaleType.CenterInside);
//this.image.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
SetContentView (Resource.Layout.Image);
m_Layout = FindViewById<FrameLayout> (Resource.Id.editable_layout);
m_Layout.AlwaysDrawnWithCacheEnabled;
this.path = (savedInstanceState ?? Intent.Extras).GetString ("path");
Title = System.IO.Path.GetFileName (this.path);
Cleanup();
DecodeBitmapAsync (path, 400, 400).ContinueWith (t => {
image = FindViewById<ImageView> (Resource.Id.imageView1);
image.SetImageBitmap (this.bitmap = t.Result);
}, TaskScheduler.FromCurrentSynchronizationContext());
btnAddImage1 = FindViewById<ImageButton> (Resource.Id.button1);
btnAddImage2 = FindViewById<ImageButton> (Resource.Id.button2);
btnAddImage2 = FindViewById<ImageButton> (Resource.Id.imageButton2);
btnAddImage1.Click += (sender, e) => {
CustomImageView bitmapView = new CustomImageView (this, Resource.Drawable.big85);
m_Layout.AddView (bitmapView);
};
btnAddImage2.Click += (sender, e) => {
CustomImageView bitmapView = new CustomImageView (this, Resource.Drawable.curled5);
m_Layout.AddView (bitmapView);
};
btnConfirm.Click += (sender, e) => {
createBitmap();
};
}
public void createBitmap(){
m_Layout.DrawingCacheEnabled;
m_Layout.BuildDrawingCache();
Bitmap m_Bitmap = Bitmap.CreateBitmap(m_Layout.GetDrawingCache());
}
XML爲ImageActivity
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:minWidth="25px"
p1:minHeight="25px"
p1:background="@color/gray_35"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/root_layout">
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:background="@drawable/red_noise_background"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="50dp"
p1:id="@+id/linearLayoutActionBar">
<ImageButton
p1:src="@drawable/ic_navigation_previous_item"
p1:layout_width="wrap_content"
p1:layout_height="fill_parent"
p1:background="@color/transparent"
p1:id="@+id/imageButton1" />
<LinearLayout
p1:layout_width="2dp"
p1:layout_height="fill_parent"
p1:background="@color/pixagramdark_red" />
<TextView
p1:text="Pixagram"
p1:textColor="@color/white"
p1:layout_weight="1"
p1:textSize="24sp"
p1:gravity="center"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent"
p1:id="@+id/textView1" />
<LinearLayout
p1:layout_width="2dp"
p1:layout_height="fill_parent"
p1:background="@color/pixagramdark_red" />
<ImageButton
p1:background="@color/transparent"
p1:src="@drawable/ic_navigation_accept"
p1:layout_width="wrap_content"
p1:layout_height="fill_parent"
p1:id="@+id/imageButton2" />
</LinearLayout>
<LinearLayout
p1:layout_width="fill_parent"
p1:layout_height="2dp"
p1:background="@color/pixagramdark_red" />
<FrameLayout
p1:layout_weight="1"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/editable_layout">
<ImageView
p1:src="@android:drawable/ic_menu_gallery"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/imageView1" />
</FrameLayout>
<LinearLayout
p1:layout_width="fill_parent"
p1:layout_height="2dp"
p1:background="@color/pixagramdark_red" />
<LinearLayout
p1:orientation="vertical"
p1:minWidth="25px"
p1:background="@drawable/red_noise_background"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="75dp"
p1:id="@+id/linearLayout1">
<HorizontalScrollView
p1:layout_gravity="bottom"
p1:gravity="bottom"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent"
p1:id="@+id/horizontalScrollView1">
<LinearLayout
p1:orientation="horizontal"
p1:layout_width="fill_parent"
p1:layout_height="fill_parent"
p1:id="@+id/linearLayout1">
<ImageButton
p1:text="Button"
p1:layout_weight="1"
p1:layout_width="75dp"
p1:background="@color/transparent"
p1:layout_height="fill_parent"
p1:src="@drawable/big85"
p1:id="@+id/button1" />
<ImageButton
p1:text="Button"
p1:background="@color/transparent"
p1:layout_weight="1"
p1:src="@drawable/curled5"
p1:layout_width="75dp"
p1:layout_height="fill_parent"
p1:id="@+id/button2" />
<ImageButton
p1:text="Button"
p1:background="@color/transparent"
p1:layout_weight="1"
p1:layout_width="75dp"
p1:src="@drawable/curve21"
p1:layout_height="fill_parent"
p1:id="@+id/button3" />
<ImageButton
p1:text="Button"
p1:layout_weight="1"
p1:src="@drawable/facial1"
p1:background="@color/transparent"
p1:layout_width="75dp"
p1:layout_height="fill_parent"
p1:id="@+id/button4" />
<ImageButton
p1:text="Button"
p1:layout_weight="1"
p1:layout_width="75dp"
p1:src="@drawable/horseman1"
p1:background="@color/transparent"
p1:layout_height="fill_parent"
p1:id="@+id/button5" />
<ImageButton
p1:text="Button"
p1:src="@drawable/thin20"
p1:layout_weight="1"
p1:background="@color/transparent"
p1:layout_width="75dp"
p1:layout_height="fill_parent"
p1:id="@+id/button6" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
的位圖也許這個鏈接可以幫助你: 的http:// stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android – 2014-09-19 13:16:52