LibGdx rectangle with one or more images attached to it - android

Is there a way by which I can draw a colored rectangle (as in shapeRenderer.filledRect() ) and attach a image to it?
I know that we can draw a Rectangle using ShapeRenderer and then SpriteBatch.draw() an image (Texture) over it.But then they are two separate objects just one drawn 'over' another.
But is there a way I can combine a rectangle and an image attached to it into one object?

Related

Masking and cut transparent image

I have two images one over other. Uppper image is having some transparent portion, I want to cut that portion and place it in sd card.
Also the below image can be zoomed in/out/scaled.
Can any one help me in this ?
I appreciate if anyone even can provide me some idea.
Create a Bitmap object to draw to that is the same size as the Upper image.
Create a Canvas object and pass this bitmap to its constructor so that you are drawing into the bitmap.
Draw the Lower image on the canvas with a transformation Matrix that represents your zoom/pan etc.
Then iterate over the pixels in the upper bitmap and the one you just drew into and set the alpha value of the pixels in the new bitmap to that in the upper image. Maybe there is another way of applying an alpha mask but I did not see one after a quick skim of the Canvas class interface - maybe looking a bit closer would reveal something.
Alternatively for better performance, use OpenGL and write a shader to do it using your two images. You can render to texture and pull the data back from the render texture. More complicated to do than the other method.

Bluring Part of an Image in Android

is there any way to blur only part of an image in android?
searched a lot but dint find any help.
most of the examples use gaussian blur which blurs full imageview.
i want to allow user to dynamically draw rectangle on imageview & on action up
area within rectangle should be blured.
any help will be really appreciated.
Bluring images on the fly is not an easy task, ask Roman Nurik (The one behind Muzei app)
He gave useful tips on this Google+ post but it's for animated images, from focus to blur.
In your case, I would say that you need to (roughly):
Get the bounds of the drawn rectangle
Get the image part that corresponds to the previous bounds
Blur on the fly the previous image part
Draw, into the same canvas, the blurred image part on top of the original image
Set up a onDrag Listener to move the drawn rectangle and do again step 1
EDIT: After re-thinking about it, computing and draw a blurred area each time the drawn rectangle move it too heavy, it won't work. The solution is probably this:
Blur the entire image and keep it into memory
Get the bounds of the drawn rectangle
Get the part of the blurred image that corresponds to the previous bounds
Draw, into the same canvas, the blurred image part on top of the original image
Set up a onDrag Listener to move the drawn rectangle to do again step 2-3-4
put the image view in a relative layout.
you detect the touch events of the user.
for each rectangle that he is drawing, you add an image view of it is size superposed to the initial one (I mean in the same relative layout) and of course with your blur effect.
you will see your image view blured part by part ...
put another layout on the half part of the image and set a translucent type background to the layout.
Once you have drawn your rectangle set alpha = 0.5 or as per your need so that your dynamic view that you have drawn will look blurred.
This is code for blur:
http://shaikhhamadali.blogspot.in/2013/07/gaussian-blur-imagebitmap-in-imageview.html
In this code computeConvolution3x3 method is used for computing the blur.For computing blur it convert the bitmap in to pixel array then it apply on those pixel. So you have to just do is get pixels array of that part of the image that you want blur.

draw multiple circles and set them as ImageView background in android

I have an image view with a (not really) complex background. The background is to be the composition of three circles, each with different dynamically set colors.
one circle, the largest, is actually a perimeter (i.e. stroke)
one circle, the second largest, is concentric with the perimetric circle
one circle, the smallest, sits at the base of the other two circles (so that it is not concentric).
I successfully create the 3-circle background using layer-list. But the problem is that I am not able to change the colors in the layer-list dynamically. Changing the color of these circles is a crucial part of the design.
So since my ImageView is part of a custom view anyway, I am now thinking of using the canvas in onDraw(Canvas canvas) to create my three circles and set them as the background of the ImageView. However, the problem with this approach is that I don't know how to set my composite image (the three circles) as the background of my ImageView.
Any snippet of code solving this problem is greatly appreciated.

Draw on imageview image in android?

Fellow Programmers,
I am new to android and I am trying to draw on a image based on giving the x and y axis of the image as the input.So that he pixel value corresponding to the coordinate gets filled with a color that I mention. Say Red color for now.
User Story: Render a image through image view and on a button click I need to pass the co-ordinate value for the image that represents the pixel of the image and fill it with red color. Keep on doing it looks like drawing on the image that I render using image view.
Is this user story is possible to do in Android? If then help me on this. I referred the draw class and canvas class and not sure how to implement.
Looking forward to ur help on developing this user story on android application.
Best,
Googler
Take a blank canvas.
Draw your image on the canvas.
Draw points on the canvas by specifying x and y co-ordinates and red color in paint.

Android: how to make a drawn shape move & how to draw just part of a shape like a 3/4 solid circle

Animation:
All the animations on the Android books I read are made on an existing image. They load an image on the SD card and use animation functions (like alpha, scale, translate and rotate) to make it move. However, what if I want to make the shapes I drew move on the screen. For example, I just draw a circle on the screen and want to make it move from left to right. How can I do this?
Painting:
Functions like drawCircle can draw complete geometric shapes but I just want to draw part of a shape, for example, a 3/4 solid circle. How should I do? If I use drawArc, there will be a 'V' recess on the circle and I want it to be flat.

Categories

Resources