I have a transparent image in my drawable folder and I'm trying to send it using an Intent. The image loads and sends just fine but it's no longer transparent and has a black bacground attached to it. This is how I'm sending the image
Intent localIntent = new Intent("android.intent.action.SEND");
localIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("android.resource://com.t4t.stickerwhatsapp/" + videoDetails.get(pos)));
localIntent.setType("image/*");
startActivityForResult(localIntent,111);
videoDetails.get(pos) is the id of the image in the drawable folder. Why is it adding a black background to my images?
Edit: It turns out my phone is adding the black bg to all transparent images that I receive it's not the code adding it before it sends.
You should get the drawable out of the resources by using the resources available from getResources().
I recommend you use:
Drawable drawable = getResources().getDrawable(R.drawable.image);
The id of an image may change and keeping tabs on it is a bad idea. If you must do this, instead you may use:
getResources().getIdentifier("image", "drawable","package_name");
If the image is still not transparent, I might try setting the drawables background color using Color.Transparent. It can be a number of issues, especially if on the other end the drawable is getting processed.
It turns out my phone is adding the black bg to all transparent images that I receive it's not the code adding it before it sends.
Related
I have a png image , when I run my android application then the white background of the image is shown ! How to make the image's background transparent ? Here is the captured photo :
Use Photoshop. Use the magic wand to choose the white pixels, then use del key on the keyboard. After that, save it and re import it to the project.
I have imported the android's example project in the following link.
http://developer.android.com/training/displaying-bitmaps/index.html
When i ran this app, I got a clean grid of images.
When i used a transparent image instead of the given ones, the transparent areas are filled with
black color.
See the image.
I couldn't remove this black color no matter whatever i change. I tried changing the grid view's background also. It didn't help.
To reproduce the problem, load the project given in the above link and change the first six items in imgUrls in Images.java with https://lh3.ggpht.com/vFpQP39LB60dli3n-rJnVvTM07dsvIzxrCL5xMiy1V4GV4unC1ifXkUExQ4N-DBCKwI=w124
Eg:
public final static String[] imageUrls = new String[] {
"https://lh3.ggpht.com/vFpQP39LB60dli3n-rJnVvTM07dsvIzxrCL5xMiy1V4GV4unC1ifXkUExQ4N-DBCKwI=w124",
There are 3 possibilities
Background Color of your layout is black that's why transparent area filled by black..
if you change the background color of layout then area color will be changed...
be sure your transparent file must be .png file
Check Also that the ImageCache uses PNG compression. The default is JPG.
In my application I want to be able to allow users to place in images onto a folder created by my app which then I put them into a stack which will be set up as an image background.
The question is how would I be able to set a background image on code?
I know you can place images in drawables and set it on xml but I want users to be able to feel free to choose from the background they prefer.
Thanks.
This is what I tried. If possible correct me cause it's not working.
Bitmap backgroundBitmap = BitmapFactory.decodeFile(backgroundFileLocation);
Drawable backgroundImage = new BitmapDrawable(backgroundBitmap);
LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout_layout_options);
ll.setBackgroundDrawable(backgroundImage);
use a linear layout and setBackgroundDrawable() once you get a drawable from the sd card by loading the image using bitmapfactory.decodefile() then use bitmapDrawable
I created an XML layout for my project with an ImageView in it. I add a default image for imageView. Now programatically I am getting that imageview and trying to change the image source using imgView.setImageBitmap(newbitmap);.
The problem is that both images are showing - the default image displays behind programatically added one.
I tried:
imgView.setImageResource(0);
imgView.setImageDrawable(null);
imgView.setAlpha(0);
imgView.setImageBitmap(null);
...but the default image is still visible.
If you are setting the background of the ImageView in the xml file, then it will remain until you clear the background. ImageView is odd in that it can display two images, background and source. Use the attribute android:src to set the source image and 'android:background' to set the background. All the methods you described will replace the source image but keep the background unchanged.
I am doing a project in which i want to fade my background image from normal to fade the same image so the text over it can be displayed properly...but i am not getting how to do it??
Try putting both images in a TransitionDrawable. This is a type of drawable that is used to cross-fade between its layers when startTransition(int) is called. See the TransitionDrawable documentation here.