I'm using following line to convert view to bitmap in android.
view.setDrawingCacheEnabled(true);
Bitmap b= view.getDrawingCache();
I am having value in view when I am converting to Bitmap, its showing bitmap value null.
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();
}
}
Use below code : just replace yourview value
YourView view = (YourView )findViewById(R.id.yourViewId);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With