android-canvas

Canvas.drawVertices(…) draws nothing

[亡魂溺海] 提交于 2019-12-10 14:26:22
问题 The next class is a view for a red triangle: public class FreeStyleViewII extends View { private final Paint paint = new Paint(); private final int[] colors = new int[] { Color.RED, Color.RED, Color.RED, 0xFF000000, 0xFF000000, 0xFF000000 }; private final float[] verts = new float[] { 1f/2f * 200f, 1f/4f * 200f, 1f/4f * 200f, 3f/4f * 200f, 3f/4f * 200f, 3f/4f * 200f }; private final Path path = new Path(); { path.moveTo(1/2 * 200, 1/4 * 200); path.lineTo(1/4 * 200, 3/4 * 200); path.lineTo(3/4

How to set canvas size?

北城余情 提交于 2019-12-10 13:03:31
问题 I have a class named SeatsPanel where I draw seats (using drawRect) in the onDraw method. The onDraw method uses Canvas as a parameter, but how do you set size of the Canvas? The reason why I'm asking this question is because this class is being inflated in another class. I know that the canvas has the default height and width of the phone, but I need to make it smaller. How can I do this? Any help would be appreciated. -Tolga- 回答1: I've tried to implement a simple application that draws a

how to make an object move in circular path?

六月ゝ 毕业季﹏ 提交于 2019-12-10 12:11:10
问题 consider two circles with (0,0) as center and 110 and 210 as radius respectively... i.e i have CENTER as (0,0) and CIRCLE 1 radius as 110 and CIRCLE 2 radius as 210. Now i need to move an object tball in between these two circles . Here is my code-- public void run() { while (isitok == true) { // perform drawing if (!holder.getSurface().isValid()) { continue; } Canvas canvas = holder.lockCanvas(); canvas.drawARGB(255, 150, 150, 10); // System.out.println("Canvas matrix -" + canvas.getm));

Draw object's trails on a SurfaceView

删除回忆录丶 提交于 2019-12-10 11:56:24
问题 I have to simulate the motion of some objects, so I have created a SurfaceView on which I draw them with a dedicated Thread. Every loop I call canvas.drawColor() to clean up all previous object's positions and to draw the new states. Everything works fine and the frame rate is decent. The problem is: what if I want to draw the trails of the objects' trajectories? In that case I have to memorize the positions for every object and, at every loop, draw all past positions that are hundreds of

How to draw on top of camera preview?

假装没事ソ 提交于 2019-12-10 11:53:46
问题 I want to draw some thing on the view which we get when our camera is on in android mobile. I do not want to take picture nor record video just that view from camera and then draw some thing on screen. Drawing on screen is will not be issue but when we turn on camera which view we get and how can we use that view in our application? 回答1: You'll want to check androids camera-API. You can get the preview to display in a SurfaceView or your own View-subclass, which can then be used to draw on.

Resize Images in Canvas

时光毁灭记忆、已成空白 提交于 2019-12-10 11:40:46
问题 I'm displaying a bitmap on Inside the ImageView and using the Canvas . ImageView : it display the whole image not matter how large the image, it compress bitmap within the width/height of Imageview. Canvas : canvas draw the bitmap but if the bitmap is larger it goes out of screen. How to same behavior for bitmap on canvas like Imageview display.? 回答1: To resize a bitmap take a look at drawBitmap method in the canvas, Each overloaded method allows you to specify a size. For example here is the

Android - User paints lines with their finger

时光毁灭记忆、已成空白 提交于 2019-12-10 11:23:15
问题 I want to build a tool on Android where the user can paint some simple objects over a picture (eg line, circle or arrow). I started trying the line part first, and indeed I could succeed on painting it. The logic is that the user taps at one point and then drags their finger, painting the line. I use a class like this (it is based on DonGru's answer here): public class DrawView extends View { Paint paint = new Paint(); float Sx, Sy, Lx, Ly; public DrawView(Context context, float x1, float y1,

Overlay Bitmap over another Android

雨燕双飞 提交于 2019-12-10 10:49:34
问题 hello guys i'm trying to get an image(Frame from resources) to overlay it over the original bitmap. so far i couldn't make my Bitmap goes into the frame as the frame always empty. the original bitmap is now showing inside the frame. here is my code that i'm using to accomplish this. Canvas canvas = new Canvas(); Bitmap border = null; Bitmap scaledBorder = null; border = BitmapFactory.decodeResource(getResources(), R.drawable.frame1); int width = bmp.getWidth(); int height = bmp.getHeight();

Android - Drawing on the different devices

痴心易碎 提交于 2019-12-10 10:36:46
问题 In my app I create a canvas and add some bitmaps on it. The problem is that the objects are adding why touch the screen. So on one screens they appear on the middle on different the same, but their position in pixels are different. I mean that I got tablet and smartphone. When I touch one the object appear on both devices (multiplayer) but its not in the same place, because its passing the position by x and y. If someone understand what I mean, can you help me? Probably it must have something

Android: How to draw on a Surfaceview which already is displaying a Camara Preview

孤街浪徒 提交于 2019-12-10 10:27:52
问题 I am trying to program an application which has to display on the mobile phone's screen what is being filmed by the front camera [The application is not recording/saving anything in the memory of the phone]. Also in case a face is filmed (and detected), it has to appear sourrended by a rectangle. To do so I'm using: A Surfaceview to display what is being filmed by the front camera. A FaceDetectionListener to detect faces in the camera input. So far the application displays properly what is