Change the opacity of black pixels in an ImageView - android

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.

Related

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 - Selective focus on a bitmap

I'm currently able to blur a whole bitmap (by resizing it down than up for example).
The effect I'm trying to accomplish is a selective blur : the result bitmap would be blurred, minus a round / oval part of it which would still be sharp :
The difficult part is that the sharp oval part could be smaller or bigger, and should be movable (its coordinates aren't always the center of the original bitmap).
I already found a solution, but I don't think of it as a good performance wise solution :
Copy the original bitmap into two different bitmaps (background and foreground)
Blur the background one
Crop the foreground one into the desired shape (round or oval)
Erase the borders of the foreground a bit (to avoid a too sharp difference between foreground and background images)
Put back the two images together
Export it as a bitmap
One another solution could be to recreate a blur algorithm which would run through every pixel of the original bitmap and apply an amount of blur higher or lower depending on the portion of the bitmap.
I finally decided to follow my first idea, using #DerGolem links. Here is the updated version of the chart :
The algorithm is quite simple:
We create two copies of the bitmap : the first one will serve as the background, while the other one will be used as the sharp part of the picture. To avoid the second one to be too sharp, we'll use a prepared mask (stored in the drawables folder)
We blur the first one as much as we want
We apply the mask to the second bitmap
We create a bitmap from those two previous steps
I created a sample demo application, hosted on BitBucket. You can clone the project and try it, the performances are much better than what I expected!
In order to achieve this, I used the following resources:
RenderScript to blur the background, much better than resizing the image down and up : 1, 2
Understand Porter/Duff
As said in the project's readme, the provided code is far from being perfect, but it works.

Wallpaper not scaling correctly when placing it as activity backgroung

I have a custom .png image set as my Android device's wallpaper.
As I understand it, wallpaper size should be 960x800 pixels but the Android device will only present the middle part of the image and the extra right and left parts are for when you scroll right and left on the screen. So I’ve taken a small image that I want it to be in the center of the screen (350x350) and filled the rest of the image with a black surrounding.
My problem is: I have an activity in my application that needs its background to be similar to the wallpaper (to imitate a blank activity with just a TextView presented on it).
I’m using this code to do so:
private WallpaperManager wallpaperManager;
private Drawable wallpaperDrawable;
private RelativeLayout rtemp;
rtemp = (RelativeLayout)findViewById(R.id.temp_layout);
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
rtemp.setBackground(wallpaperDrawable);
But the screen appears to have the wallpaper as a whole and not just the middle part anymore (it basically shrink down the image) and it is not consistent with the regular wallpaper anymore.
Are there any suggestions on how to solve it? Is there a way to avoid image shrinking on the activity or is there a way to make the image not spread as the wallpaper screen?
Thanx a lot!
Better use FrameLayout which contains both your RelativeLayout over an ImageView. Imageview gives you the options to scale your image & some furthermore customization.

How to fill the drawable region in an imageView with another drawable?

so I'm trying to find the region of the current image in the ImageView and fill that region with a different image. Here is the original image Empty Circle inside an imageView. The imageView has a drawable of a circle inside. Then I'm trying to make it into something like this Circle filled with image inside an ImageView when a user chooses an image. I don't want to manually Photoshop a circle image. I am just hoping to fill the region with another image. I have tried SRC_IN method from AlphaComposite, but for android, I can't convert from BitMap to graphics2D. If anyone knows how to solve this using the BitmapFactory in android, I would really appreciate your help. Thank you.
The other solution besides Bitmaps, may be too simple for whatever you are trying to achieve otherwise I think it would have occurred to you. I'm just pointing it out in case you have "code blindness" and are trying to over-engineer the solution because you've worked on it for too long (we've all done it)
It is to have that circle/shape image saved as a png with the area you want filled being transparent then set it as the drawable for an ImageView (etc.) then in a RelativeLayout lay this view over the image you want to fill the area and apply a transparent background to the shape view OR simply set the fill image as the background for the shape view.

How to get black shadow around the image dynamicaly?

I am working on image processing i have achieved color effect using ColorMatrix but i cant understand how to achieved one effect that is not on whole image but only around the image like i have attached image. Actually i m working on image editor app like : BeFunkey
Here original image and processed image i have attached. You can see in effect on second image that is only around the image black shadow. Please can anybody tell me how to do this. Thank you in advance.
You need to set RGB colors of you bitmaps. Have a look over android-image-filter
This demo will fulfill your requirements.

Categories

Resources