I am writing the process of overlapping two images on Android as follows.
Bitmap imageA=loadImage();
Bitmap imageB=loadImage();
Bitmap output = Bitmap.createBitmap (width, height, Config.ARGB_8888);
Canvas canvas = new Canvas (output);
canvas.drawBitmap (imageA, 0, null);
canvas.drawBitmap(imageB,0,0,null);
I'd like to overlap imageB with blurring boundaries.
Instead of blurring the image itself, we want the boundary to change smoothly.
For imageA and imageB, the blue frame shown below is Bitmap size, and both are the same size.
The background is transparent (0x000000
), and the colored areas are completely opaque (alpha value is 255).
I saw an article saying that Bitmap.extractAlpha() should be used well, but I didn't know how to use it...
android
I'm not good at imaging, but it seems interesting, so I tried it.
I think there is a smarter way.
For the time being, I came up with a method of drawing while changing the transparency from the outside to the inside of the image.
When I looked at the image that was processed and the other image, it looked like that.
If you change the value of the repeated process, you can change the size of the blurring.
private Bitmap featuring (Bitmap src){
int width = src.getWidth();
int height = src.getHeight();
Bitmap dst=Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_888);
Canvas canvas = new Canvas (dst);
Paint paint = new Paint();
for (inti=1; i<255;i++) {
paint.setAlpha(i);
Rect = new Rect(i, i, width-i, height-i);
canvas.drawBitmap(src, rect, rect, paint);
}
return dst;
}
Additional
I'm sorry. I didn't read the question well.
So the blue frame was the size of the image...
This answer is not helpful.
Additional 2
As for the power technique, I tried to blur the opaque area as the range of the picture after looking at the alpha value.
The assumption is that the part to which you want to blur must be rectangular.
What do you think of it like this?
private void hoge(){
// back side
Bitmap img1 = BitmapFactory.decodeResource(getResources(), R.drawable.img1).copy(Bitmap.Config.ARGB_888, true);
// Front side (the side where blurring is placed)
Bitmap img2 = BitmapFactory.decodeResource(getResources(), R.drawable.img2).copy(Bitmap.Config.ARGB_888, true);
imageView.setImageBitmap(margeBitmap(img1,img2));
}
private Bitmap marginBitmap (Bitmap img1, Bitmap img2) {
intw = img1.getWidth();
int = img1.getHeight();
IntBuffer buff=IntBuffer.wrap(new int[w*h]);
img2.copyPixelsToBuffer(buff);
Point p1 = new Point (0,0);
Point p2 = new Point (0,0);
boolean p1flg = false;
// Obtain first and last opaque
for(inty=0;y<h;y++){
for(intx=0;x<w;x++){
int pixel=buff.get((y*w)+x);
if((pixel&0xff000000)==0xff000000){
if(!p1flg){
p1.set(x,y);
p1flg = true;
}
p2.set(x,y);
}
}
}
// IMG2 FRAME BLURING TREATMENT
Bitmap dst=img1.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas (dst);
Paint paint = new Paint();
for (inti=1; i<255;i++) {
paint.setAlpha(i);
Rect = new Rect(i+p1.x, i+p1.y, p2.x-i, p2.y-i);
canvas.drawBitmap(img2,rect,rect,paint);
}
return dst;
}
There is a function to mask blurry images, so
I feel like I can only use the standard API to achieve images like this one.
Code
BlurMaskFilter1 = newBlurMaskFilter(10,BlurMaskFilter.Blur.NORMAL);
circuit1.setMaskFilter(filter1);
canvas.drawCircle(canvas.getWidth()/4, canvas.getHeight()*2/4, canvas.getWidth()/6, circle1);
You can use arguments to change the blurring inside or outside.
BlurMaskFilter.Blur.INNER
BlurMaskFilter.Blur.OUTER
BlurMaskFilter.Blur.SOLID
This is a postscript.
If it's blurring about the image, it's not good if you only use the method you wrote.
Bitmap.extractAlpha() was used in the stack overflow.
https://stackoverflow.com/questions/3580051/how-to-prevent-androids-drawbitmap-from-only-drawing-black-images
© 2024 OneMinuteCode. All rights reserved.