Yugandhar Babu
Yugandhar Babu

Reputation: 10349

getDrawingCache() always returning null

I want to capture The content of ImageView by using DrawingCache. I written the below code.

iv1 = (ImageView)findViewById(R.id.iv1);
iv2 = (ImageView)findViewById(R.id.iv2);            
iv1.setDrawingCacheEnabled(true);
Bitmap myScreenshot = iv1.getDrawingCache();
iv2.setImageBitmap(myScreenshot);

But I am getting only one image on screen. Later I came to know myScreenshot is null

I saw many posts regarding same problem, but no proper solution.

I thought any permissions we have to add in manifest ? or root permission required to achieve this ? Please help me regarding this problem.

Upvotes: 6

Views: 9990

Answers (4)

Richa
Richa

Reputation: 700

call getDrawingCache() in onWindowFocusChanged() and not in onCreate(), then you will not get null.

Upvotes: 2

Mady Cool
Mady Cool

Reputation: 109

You din't do iv1.buildDrawingCache(true); add line before
Bitmap myScreenshot = iv1.getDrawingCache();

Upvotes: 1

aqs
aqs

Reputation: 5672

Try calling buildDrawingCache() before getDrawingCache()

EDIT: Call getDrawingCache(), after the page have loaded, instead of onCreate

Upvotes: 10

NagarjunaReddy
NagarjunaReddy

Reputation: 8645

imageview.setBackgroundResource(R.drawable.imageview);                 

imageview1.setBackgroundResource(R.drawable.imageview1); 

use this two images is screan

 <RelativeLayout
    android:id="@+id/item"               
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="320dp"
        android:layout_height="486dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/iv1" />

    <ImageView
        android:id="@+id/ic_launcer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/iv2" />

</RelativeLayout>

Upvotes: 0

Related Questions