I have an activity where I get an image and display it full screen, I want to draw a rectangle 600 x 600 for example over the image, I want the image to be darker and inside this rectangle to be bright 100% , and with my finger to change this rectangle's position (following my finger) and when iI click a button to be able to crop the image , to get only what it is inside this rectangle (bright area), how can I create this ?
You can store all the coordinates in an arraylist and draw a clipPath line in ActionMove of onTouchListener
clipPath = new Path();
clipPath.moveTo(tdownx,tdowny);
for(int i = 0; i<your_array_list.size();i++){
clipPath.lineTo(your_array_list.get(i).getY(),your_array_list.get(i).getX( ));
}
canvas.drawPath(clipPath, paint);
You can see the output at this YouTube video
Related
I know the x and y coordinates in an bitmap and want to draw a rectangle there. I think this picture illustrates what I want.
Lets say I want to draw a green rectangle over the red one. I know the coordinates of the top left corner and the coordinates of the bottom left corner. Usually it should not be a problem. But I display the bitmap in an Imageview. I use this code to map the coordinates form the bitmap to the coordinates in the canvas of the imageview. For image_view_width and image_view_height I use the getHeight and getWidth form inside of the Imageview.
This solution works on my real device but on the emulator it shows the rectangle on the wrong position. Can someone help me and tell me what is wrong?
I am trying to add an image on top of another image. The one on the top is a blurred image. I am using the following code to try and achieve this.
//First image as a background(full size)
mCanvas.drawBitmap(canvasBackImage, 0, 0, null); //draws fine
Rect rectangle = new Rect(0,0,200,200);
//Second image on top blurred 200px x 200px rectangle
mCanvas.drawBitmap(blurBuilder.blur(appContext, canvasBackImage, mX, mY), null, rectangle, null);
The image is drawn fine with the above code at coordinate 0,0 of the canvas however, if I modify the above code's line three to the following, it doesn't add the image at the 100,100 coordinate of the canvas.
Rect rectangle = new Rect(100,100,200,200);
I also tried it with 50,50 coordnate and it works. So Changing it the following works too.
Rect rectangle = new Rect(50,50,200,200);
I have no idea why this is not working as I expect it to. Am I doing something wrong?
My ultimate objective is to blur the image at the exact location that the user touched. So if user touched in the middle of the screen then that part of the image will be blurred out.
I moved the above code in onDraw method and it seems to be working as expected now.
Before I had it in a different method which was being called manually on a button click.
I m new to android development, currently working on App which is working on canvas and images ...
But i m stuck in middle of the process.
I want to implement such a functionality that user touches an edges of the image and if he/she drags thet image, image will be scaled ..
I googled a lot and more of it but couldnt find any tutorial or Demo s ..
Hope you SO guys help me . Such a functionality is provided by galaxy Note like this below image ..
Try this.
If user touch the image at right side and will drag that right side then the below code will scaled the image and draw scaled image.
Bitmap bmpImage;
Rect src = new Rect();
Rect dst = new Rect();
src.left = initial_Start_pos_X; // initial Start X postion of image
src.top = initial_Start_pos_Y; // initial Start Y postion of image
src.right =initial_End_pos_X; // initial End X postion of image
src.bottom = initial_End_pos_Y; // initial End Y postion of image
dst.left = initial_Start_pos_X;
dst.top = initial_Start_pos_Y;
dst.right = Draged_Pox_X; // Drag X position of image
dst.bottom = initial_End_pos_Y;
canvas.drawBitmap(bmpImage, src, dst, paint); // This line will scaled the image according to dst rect. It will take the image from src rect and draw in dst rect. so it will scaled the image.
You have to invalidate each time the view when you are dragging the image side. you have to invalidate the view in ONTOUCHMOVE.
So you have to check first, That which side of image is touched by user and dragging then you have to modify the above code.
Above code will show only scaled image in right side only
I have rotated a dial around its center with the helop from the link below:
http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/
Now I have an icon beside the dialer and I need to rotate it around the dialer, along with the dialer in a circular path.
private void rotateLogo(float degrees){
Matrix nMatrix = new Matrix();
Bitmap peopleOrg = BitmapFactory.decodeResource(getResources(), R.drawable.peoplelogo);
float translateX = dialerWidth / 2 - dialerWidth / 2;
float translateY = dialerHeight / 2 - dialerWidth / 2;
nMatrix.preTranslate(-turntable.getWidth()/2, -turntable.getHeight()/2);
nMatrix.postRotate(degrees, translateX, translateY);
nMatrix.postTranslate(turntable.getWidth()/2, turntable.getHeight()/2);
Bitmap peopleScale = Bitmap.createBitmap(peopleOrg, 0, 0, peopleOrg.getWidth(), peopleOrg.getHeight(), nMatrix, true);
peopleLogo.setImageBitmap(peopleScale);
peopleLogo.setImageMatrix(nMatrix);
}
This just causes the image to rotate around its own center and not around the dialer's center point.
I cant find out where i am wrong :(
Updates
I basically need the logo to move in a circular path and be a clickable view.
Tried using rotateAnim but the view doesnt animate and i have trouble getting the onclick event.
Would like any help that can rotate the same using matrices
Try only rotate with peopleOrg width and height.
nMatrix.postRotate(degrees, peopleOrg.getWidth()/2, peopleOrg.getHeight()/2);
Update :
Now that you let me know that your logo should be a clickable view, merging the logo image with your dialer is not applicable. To rotate the logo view around the center of dialer you should be actually calculating the (top,left) point for your logo view and moving it around, than just rotating it.
Use sine and cosine functions to get the point on the circumference of an imaginary circle for drawing your logo view.
This post will help you with calculations : How do I calculate a point on a circle’s circumference?
I have two images.
An image with a red rectangle, and image all white. I would like to paint with your finger on the white image only where the other image is the red rectangle.
The image with the red rectangle should not be visible.
How can I do?
Create bounds for each image, e.g. with a Rect set to the cords of each image (position & size). In the view where your overriding onDraw() in, set the onTouchListener to the view itself.
In onTouch() check the event.getX()/getY() is within the bounds of the white image. Then use whiteImage.setPixel() to set the individual pixels of the Bitmap image. Alternatively use Canvas.drawPoint() instead of manipulating white bitmap image itself.
In regards to not displaying the red rectangle... just don't draw it?
Edit:
To your comment about non square/rect shapes. I would still check for the touch event in the rect and then pass it to the image if it has hit the shape.
Within the shape (I'm assuming it is a bitmap) you would do Bitmap.getPixel(x, y) and see if it is == to Color.White, if it is.. change it to whatever colour!