I\'m using following line to convert view to bitmap in android.
view.setDrawingCacheEnabled(true);
Bitmap b= view.getDrawingCache();
I am
This could work
public static Bitmap getBitmapFromView(View view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
view.draw(canvas);
return returnedBitmap;
}
Try This :
LinearLayout view1 = (LinearLayout) findViewById(R.id.linear1);
ImageView my_image = (ImageView) findViewById(R.id.my_imageView);
Bitmap b = Bitmap.createBitmap(view1.getWidth(), view1.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
view1.draw(c);
my_image.setImageBitmap(b);
Hope it helps you.
Thanks.
Use below code : just replace yourview value
YourView view = (YourView )findViewById(R.id.yourViewId);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
Reference
Activity Class In this Class I Convert the Layout(View) into Image.
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class ImageActivity extends Activity {
LinearLayout layout=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_convert);
layout=(LinearLayout)findViewById(R.id.layout);
((ImageView)findViewById(R.id.ImageView01)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bitmap map=ConvertToBitmap(layout);
Log.v("BitmapObject", map.toString());
}
});
}
protected Bitmap ConvertToBitmap(LinearLayout layout) {
Bitmap map;
layout.setDrawingCacheEnabled(true);
layout.buildDrawingCache();
return map=layout.getDrawingCache();
}
}