suppose my bitmap is like
This image is actually in square transparent. I want to get the only viewable points as array so I can bound it and handle touch event on canvas. Right now it is square so when I touch at the corner of the image it still detect touch event on image. i don't want to do like this. Only if user clicked on viewable part then only action would be taken otherwise not.
For temporary I have used radius of image from center point it works fine but accurate, also if this image triangle part length is long then if it remain in square format user fill/get event on image outside.
I have used canvas to draw bitmap. Is there any other way or easy way to do this thing and handle event.
I have seen many games in that they used like custom shapes and touch event fire only on display part of object, how could i achieve this things.
Take a look at coordinates:
Android Canvas Coordinate System
and
http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/src/com/android/spritemethodtest/CanvasSprite.java?r=150
Which goes into sprite:
http://p-xr.com/android-tutorial-how-to-paint-animate-loop-and-remove-a-sprite/
This may help too:
http://www.droidnova.com/playing-with-graphics-in-android-part-vi,209.html
Some of that should be helpful.
Related
I'm developing an android app in which I want to integrate a feature using which user can take screenshot, doodle something on it and then send it via mail.
How to implement this? I just need a pen for doodling and an eraser to erase last doodle.
Take a look at this library :
ActiveDoodle
You can display two ImageViews on top of each other: the bottom one containing the photo, the top one containing an initially transparent Bitmap. In the top ImageView's onTouchEvent() method you can transform touch events into strokes of pen applied to the bitmap using a Canvas. You might want to read up on MotionEvents and Canvases.
After the user is done with doodling, you can load the screenshot to a Bitmap, rescale the doodle bitmap to match the screenshot's size, and draw in on top, again using a Canvas. Reading about Porter/Duff algebra will probably prove useful with applying an XferMode to a Paint.
I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?
I need some activity with image cropping, but without getting crop image, just need coordinates angles of rectangle area on image which i can move and resize. How i can make this or where i can find such library with this functional? Sorry for my bad English.
For your purpose you better to use Android Canvas. When you touch a particular point you can get details of that point using 'OnTouch'(http://developer.android.com/reference/android/view/View.OnTouchListener.html) method in android.
I want to crop my image which is being displayed on an ImageView. How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. The image below illustrates a demo of something I would like to develop.
P. S. I am not quite sure how to phrase my question.
What I want:
http://imageshack.us/photo/my-images/832/customcropbox.jpg/
The final solution I came up with after ample research was:
Extend ImageView to make my own custom view.
#Override onDraw method and do my custom drawing there in that method.
Implement onTouchListener on the view to get the touch events and process them according to their position.
e. g.
I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method.
Edit:
I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out.
Heartache.
I want to be able to dynamically place image(s) over another image in my app.
Consider the first image as background and the other images to be on top level, I will also need to move those top level images (change their x and y on the screen) by code too.
Imagine, for example, a sea in which the user places fish and sea animals, then those sea animals start to move here and there on the screen: it will be like that.
How can I do this? If you don't know but remember any simple program or demo that does that, it will be also very welcome!
Thank you!
There is, of course, more than one way to do this, but I would say that the best way to do it would be to create a custom View (class that derives from View) and have this handle your bitmap drawing and all of your touch events.
There's a lot of code to write for loading the Bitmaps and keeping track of all of their positions (and then drawing them to the canvas in onDraw), but if you start really small by just allowing one image to be drawn and dragged around the screen, you can build on that and keep your code organized.
You would need to override onDraw(Canvas) and onTouchEvent(MotionEvent) in your custom View. You'll load your bitmaps with BitmapFactory (decodeResource method if you're including your images as resources in your project) and you'll need to remember to call recycle on your bitmaps when you're no longer using them.
In onDraw, you draw your bitmaps to the canvas at a specific location using Canvas.drawBitmap. There are two overloads of this method you can choose from, one that takes the top and left coordinates of the bitmap as floats (and therefore performs no scaling or stretching) and one that takes a destination and source rectangle to perform scaling, stretching and placement.
I always use the latter as it gives me finer tuned control. If you choose this route, you'll want to keep two Rect instances and a Bitmap instance for each image being drawn, update them in the touch events and draw them to the canvas in the draw event.
When something changes inside your view (as in the case of a touch event), call invalidate() method and the framework will know to redraw everything which triggers your onDraw method.