Android: transparent background for custom drawable - android

I drew up a custom drawable icon in MS paint, but when I load the image it has a white background instead of transparent, how do I fix this?

MS Paint probably saved this without a transparent background. Id recommend using something like GIMP or Paint.NET to create this icon. They are both available free.
You probably need to save it as either a .gif file or a .png file too, as these are compatible with transparency (and Android).

I think you have to use better editor for your purposes, which could make the background of your image transparent. MS Paint has no such possibilities.

Related

How to import png without background android studio

I want to be able to use external images in my android app,but i don't know how to deal with them,in the best case scenario they have a grey background:
How do i remove the grey background or any background to have a clean icon like the clip art that already exists in android studio(I already tried with apps and it's still drawing the background)
Please make sure the image is .svg vector and not png and follow this to import. stackoverflow.com/a/67056210/7093155
I think the problem with the png you are using is that the background is not entirely transparent. If you are certain it is, then setting the background with android:background="#android:color/transparent"

rectangular box with one side diagonal

I want to create a custom View similar to this image. More specifically, the dark "number of riders" view. I don't want to use an image for background. I need a drawable xml for the background.
I am new to Android so any help would be appreciated.
The best way to do that will be to use a 9-patch drawable file and set it as the background of the TextView.
Here is how you can do that: http://en.miui.com/thread-26099-1-1.html
Or you can create an SVG and use that as background. The easiest way to do that would be to make a png image and convert it to SVG file using online converters.
How to convert a PNG image to a SVG?
There is more complicated way to archive it like drawing on a canvas and using that as background, But I would recommend you to use 9-patch file.

Android - Draw on Canvas made from .gif

I have a custom view where normally I was using .png files to draw onto in a canvas and that worked fine but now my requirements are to use .gif files and for some reason the same code will not work. Is there something specific about .gif files that doesnt allow android canvas objects to draw on bitmaps made from them?
Apparently you cannot draw on a canvas created from a .gif file. Once I was able to convert the .gif to .png I was able to draw on the canvas again.
Actually, I can draw GIF files on canvas, but all transparent colours turn into white! I assume it is just a bug, related to the new parameter inPremultiplied in Bitfactory.Options which probably was not tested properly.
I am really frustrated with that, since now I have to replace GIFs by PNG in all my previous applications. (Fixing the bug in the following version doesn't make any difference, since there will still be models, not supporting GIF transparency.)
Indeed GIF file has it own advantage. It doesn't support alpha or true colour, but it has transparent index which in many cases is what actually needed. If you want PNG files to be not crucially bigger in size than GIF (I assume this is the main reason for using GIF instead of PNG), convert PNG files from true color to index (colormap) format (most of graphic editor, including GIMP and Photoshop support that), which works OK with KitKat. You will still lose size, but no mare than 1%.

Android: how to make a bitmap border transparent?

I have a bitmap and I just want to show central circle area. How to hide the corner area? Actually, it would be great if I could make any area transparent (e.g. make it a ring)?
Convert the bitmap to a transparent PNG - you can use the free Gimp application. Load your picture in Gimp, select the central circle area, copy, then paste as new image. Should automatically make the area around it transparent. Then just save as a PNG file and use that in your Android app.
UPDATE
Here's an answer I found for defining a color to be transparent: Android bitmap mask color, remove color

android transparent picture

do you know how to make a certain part of a picture (jpg) semitransparent, like in the attached image?
Just use a PNG image instead. Problem solved :)
JPEG doesn't support transparency. Can you use a 32-bit PNG instead?
If you have an existing image that you want to apply some transparency pattern to, you will need to create a Bitmap object in code, draw your image, then set some flags to allow you to draw the transparency levels over it, a bit like a Photoshop layer mask. I did a search for Android alpha masking, and found this blog post.
Err - I may be utterly confused here, but why not just use setAlpha(int alpha) on the inflated ImageView?
That seems to work fine on a .jpg for me.
Or is it only part of the image that should be transparent? Hard to see the 'sample image'.

Categories

Resources