简体   繁体   中英

Get bitmap from ImageView

I have a list view which contains images and images are loaded at run time using HTTPClient. Loading is working fine. Now i want to get bitmap image from imageView in that listview. But when i do it gives NULLPointerException.

I am using this code to get BitMapImage.

Bitmap bm=((BitmapDrawable)imageView.getDrawable()).getBitmap();

I don't know where is the problem.

Here is complete code

    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i("OfferListner","Favourite called");
            ImageView imageView1 = (ImageView)v.findViewById(R.id.listImage);
            Bitmap bm=((BitmapDrawable)imageView1.getDrawable()).getBitmap();
            FileOutputStream fos;
            try {
             fos = mContext.openFileOutput(imageView1.getTag().toString(), Context.MODE_PRIVATE);
             bm.compress(Bitmap.CompressFormat.PNG, 100, fos);
             fos.close();
            }
            catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
               } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
               }

        }
    });

我认为您在查找View时遇到问题。您的代码很清楚,这里没有错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM