0

I am using Canvas.drawBitmap() to render a png file into a custom View that I created (creating my own custom button). Everything is working okay except that the PNG has a transparent background in photoshop, but it does not appear to be transparent in my android layout. The layout is a listview element.

I create the image with:

    `BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig = Config.ARGB_8888;
    this.image = BitmapFactory.decodeResource(context.getResources(), imageResId, opt);`

I render the image with:

     `protected void onDraw(Canvas canvas)
     {
         canvas.drawColor(Color.TRANSPARENT); 
         canvas.drawBitmap(image, WIDTH_PADDING / 2, HEIGHT_PADDING / 2, null);
     }`

At the moment WIDTH_PADDING and HEIGHT_PADDING are both 0 but I don't think that is relevant.

The PNG itself is created in Photoshop. I just did New File --> Transparent Background --> And drew a red oval then saved as PNG.. The PNG shows up with White where I expect it to be transparent.

Photoshop File photoshop file http://www.supercars.net/bb/redovalbutton.png

Android View photoshop file http://www.supercars.net/bb/myview.png

I call it up in my xml with:

com.busanbar.busanbardev.pmchat.PMCommentResendButton  
android:id="@+id/resendButton"  
android:layout_width="wrap_content"  
android:layout_height="wrap_content"  
android:focusable="true"  
android:focusableInTouchMode="true"  
android:layout_weight="1"  

How can I make the white go transparent so I can see the gray background texture in my listview container?

Daniel Guillamot
  • 843
  • 2
  • 9
  • 18

1 Answers1

0

I used android.graphics.Canvas.Canvas(Bitmap bitmap) to do the same

Bitmap b = BitmapFactory.decodeResource(con.getResources(), R.drawable.name_of_png);
Canvas canvas = new Canvas(b);

Hope this will solve your issue.