Getting Bitmap from drawable object

by Devin Yu » Wed, 14 Apr 2010 03:03:48 GMT


Sponsored Links
 Hi all,

I got a drawable object from Res ID. But I want to know its
coresponding bitmap file.
Any body can tell me how to do it?

Thanks.

--



Other Threads

1. Detecting changes in maps

Hi,

how do I detect changes of boundaries and zooms in a map? Is there an
event that is called whenever there is a drag or a zoom? I want to
update the overlays when this happens with new data requested from a
web server.

Any ideas are appreciated. Thanks!

-- 

2. Scroll View

package test.Test;
import android.app.Activity;
import android.app.SearchManager.OnCancelListener;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast;
import java.net.*;
import java.io.*;

import org.apache.http.util.ByteArrayBuffer;

public class test extends Activity implements OnClickListener
{
    /** Called when the activity is first created. */
        ImageView i[] = new ImageView[10];
        int j;
        String names[] = new String[10];
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        LinearLayout m = new LinearLayout(this);
        for(j=0;j<10;j++)
        {

        //DownloadFromUrl("google.jpg","test.png");
        i[j] = new ImageView(this);
        //i[j] = new ImageView(this);
        i[j].setImageResource(R.drawable.icon);
                i[j].setAdjustViewBounds(true);
            i[j].setLayoutParams(new
Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
                m.addView(i[j]);
                names[j]=j+"";
        i[j].setOnClickListener((OnClickListener) this);
        }
                //i[1].setImageResource(R.drawable.icon);
                //i[1].setAdjustViewBounds(true);
            //i[1].setLayoutParams(new
Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
                //m.addView(i[1]);
                //i[1].setOnClickListener((OnClickListener) this);
                setContentView(m);
    }
                public void onClick(View v)
                {
                        int j;
                        String s = new String();
                        for(j=0;j<10;j++)
                        {
                          if(v == i[j])
                          {
                                  Intent intent=new 
Intent(test.this,next.class);
                                  intent.putExtra("Name",names[j]);
                                  final int result=1;
                                  startActivityForResult(intent,result);
                                //s=j+" rajeev";
                                //Context context = getApplicationContext();
                                //Toast.makeText(context,s, 
Toast.LENGTH_SHORT).show();
                                //break;
                          }
                        }
                        /*if(v == i[1])
                        {
                                Context context = getApplicationContext();
                                Toast.makeText(context,"Second", 
Toast.LENGTH_SHORT).show();
                        }*/
                }
                public void DownloadFromUrl(String imageURL, String fileName)
                {  //this is the downloader method
            try {
                    URL url = new URL("http://web.iiit.ac.in/
~rajeshuni.rajeev/orange/" + imageURL); //you can write here any link
                    File file = new File("/data/data/
test.Test/"+fileName);

                    long startTime = System.currentTimeMillis();
                    Log.d("ImageManager", "download begining");
                    Log.d("ImageManager", "download url:" + url);
                    Log.d("ImageManager", "downloaded file name:" +
fileName);
                    /* Open a connection to that URL. */
                    URLConnection ucon = url.openConnection();

                    /*
                     * Define InputStreams to read from the
URLConnection.
                     */
                    InputStream is = ucon.getInputStream();
                    BufferedInputStream bis = new
BufferedInputStream(is);

                    /*
                     * Read bytes to the Buffer until there is nothing
more to read(-1).
                     */
                    ByteArrayBuffer baf = new ByteArrayBuffer(50);
                    int current = 0;
                    while ((current = bis.read()) != -1) {
                            baf.append((byte) current);
                    }

                    /* Convert the Bytes read to a String. */
                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(baf.toByteArray());
                    fos.close();
                    Log.d("ImageManager", "download ready in"
                                    + ((System.currentTimeMillis() -
startTime) / 1000)
                                    + " sec");

            } catch (IOException e) {
                Context context = getApplicationContext();
                                Toast.makeText(context,"internet problem",
Toast.LENGTH_SHORT).show();
            }

    }
}
There is no XML file for this activity.How to add scrolling option
here.

Thanks.

-- 

3. Hello World doesn't work

4. Android LBS Apps

5. LVL - Yay or Nay?

6. AsyncQueryHandler vs AsyncTask

7. How to get current focus view object in Service?