Search code examples
androidcanvasbitmapdrawableandroid-6.0-marshmallow

Set image bitmap not working in android marshmallow


When I set a Bitmap in an ImageView using the set image Bitmap method it works fine in android kitkat but in Marshmallow it do not work, I tried it by making the copy of the image Bitmap but no success, please help me in the issue any help will be appreciated

 PictureCallback cameraPictureCallbackJpeg = new PictureCallback() 
  {  
    @Override
    public void onPictureTaken(byte[] data, Camera camera) 
    {
      // TODO Auto-generated method stub   
      Bitmap cameraBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

   int   wid = cameraBitmap.getWidth();
     int  hgt = cameraBitmap.getHeight();

    //  Toast.makeText(getApplicationContext(), wid+""+hgt, Toast.LENGTH_SHORT).show();
       newImage = Bitmap.createBitmap
                                        (wid, hgt, Bitmap.Config.ARGB_8888);

      Canvas canvas = new Canvas(newImage);

      canvas.drawBitmap(cameraBitmap, 0f, 0f, null);

     Drawable drawable = getResources().getDrawable(R.drawable.mark3);
        drawable.setBounds(20, 30, drawable.getIntrinsicWidth()+20, drawable.getIntrinsicHeight()+30);
        drawable.draw(canvas);


        lastimage = newImage.copy(newImage.getConfig(), true);


        if (newImage != null && !newImage.isRecycled()) {
            newImage.recycle();
            newImage = null;
        }

        imageview_visinon.setVisibility(View.VISIBLE);
        imageview_visinon.setImageBitmap(newImage);





        linear_capture.setVisibility(View.GONE);

        linear_okcancelpic.setVisibility(View.VISIBLE);

    }
  };

Solution

  • Sometimes bitmap is too large. Thats why imageview turns blank! I think that here you can find what you need: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html