Transparent Image appears black on a Cached Bitmap - android

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.

Related

Change the opacity of black pixels in an ImageView

App State right now
I am making an app in which i want the background scenery/picture to be visible in the black sketch only and the reset of the part of the image should stay opaque. Right now i have made front Imageview transparent to some value but that is not what i want ,i want to change the opacity of black pixels only.
ImageView frontImageView = findViewById(R.id.image);
Bitmap front = BitmapFactory.decodeResource(getResources(),
R.drawable.front);
front=GrayscaleToBin(front);
front.setHasAlpha(true);
frontImageView.setImageBitmap(front);
imageView.setImageAlpha(150);
i have searched a lot but couldn't find a solution to this problem. Any help is appreciated.
I would recommend to make changes in original image from some other tools such as Paint or Photoshop etc and then load image in app.
Since making changes on current image which you are having will again take some time to load unnecessary.
Better process image in other 3rd party tool and use as it is in app.

Skip transparent background in an image when setting an image as background in android

I am working on a project in which I am using a lot of images. My friend has designed all the images in photoshop and all those images are of my required size.
But the problem is that when my friend exported those images from the photoshop, he exported those images with a transparent background and that transparent background with the image makes the frame size bigger than required. And when I set that image to some ImageView, it expands to the whole screen due to its bigger frame size.
Now my question is that Is there a way to set image in imageview so that the transparent part is automatically ignored and the image of my required size just sets into the imageview. Or It is required to crop those images in photoshop and then use those images.
I am sorry if someone couldn't understand the question but I can elaborate if asked.
The way I would do it would be just edit them in photoshop, but I found another way if you want to look into it. Its called webP and you can check it out here. With this you can skip the transparency, but I think the size would stay the same, You can try it out if you want though.
Hope this helps!

Android Image Asset Opacity

Every image asset I add to my project on Android Studio gets added with an opacity of something like 0.5 and I'm unable to change its opacity programmatically using setAlpha method.
I'm adding it as an Action Bar and Tab Icons type and as Asset Type: Image.
Anyone else had this problem? The asset having an opacity of 1 is quite important for what I'm trying to do.
profileButton = (ImageView) findViewById(R.id.profileButton);
profileButton.setAlpha(1f);
SOLVED: Wasn't anything Android related. Sorry.
You can not change alpha of your drawable with View.setAlpha() method.
You should create a drawable with no alpha (value:1.0f) and then change alpha of the view if needed.
Drawable is the source used to generate the Bitmap that will be used to fill the ImageView or other elements. Then your view has its own alpha display settings that you can dynamically change.
In your specific case you have to edit your image sources to get them with no alpha, I think you have no other choices. If they are vector resources you have just to change alpha values in source files.

PNG image not showing in Eclipse ImageView

I am using the Eclipse drag 'n drop feature to add a PNG image to my app UI.
When I drag the ImageView widget from the menu into the UI area it asks me to select the image from a list. I have named the picture image1 and when I select it there is just a placeholder image (a red cube with Aa in).
I have tried re-sizing the image and using different images. The placeholder image is visible on my UI but nothing I have tried can made the actual picture I have put in my xhdpi folder show up on the screen.
Any help much appreciated.
I'm not entirely sure why but when I changed the filename from image1.png to image2.png it worked.
The placeholder image that I kept seeing was listed higher up in the hierarchy as image1-web.png so I wonder if that was taking precedence.

Trying to use transparent image but a black background is being added

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.

Categories

Resources