Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Views to bitmaps?

Tags:

android

bitmap

I have two Views (Textview & ImageView) in the FrameLayout, I want to save the image with text. For this, I covert the View to a bitmap.

My xml is:

<FrameLayout       android:id="@+id/framelayout"      android:layout_marginTop="30dip"      android:layout_height="fill_parent"       android:layout_width="fill_parent">       <ImageView            android:id="@+id/ImageView01"           android:layout_height="wrap_content"            android:layout_width="wrap_content"/>      <TextView android:id="@+id/text_view"           android:layout_marginTop="30dip"           android:layout_width="wrap_content"            android:maxLines="20"           android:scrollbars="vertical"           android:layout_height="wrap_content"/>  </FrameLayout> 
like image 872
RajaReddy PolamReddy Avatar asked Aug 26 '11 05:08

RajaReddy PolamReddy


People also ask

How do I create a Bitmap in canvas?

To create a Bitmap from a resource, use the BitmapFactory method decodeResource(): Bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.

What are bitmaps in Android?

A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use.

What is Bitmap in canvas?

Canvas is the place or medium where perfroms/executes the operation of drawing, and Bitmap is responsible for storing the pixel of the picture you draw.

Is drawing cache enabled deprecated?

getDrawingCache() has been deprecated.


1 Answers

How to convert View into Bitmap

FrameLayout view = (FrameLayout)findViewById(R.id.framelayout);  view.setDrawingCacheEnabled(true);  view.buildDrawingCache();  Bitmap bm = view.getDrawingCache(); 
like image 132
Niranj Patel Avatar answered Oct 06 '22 11:10

Niranj Patel