android-canvas

VideoView is not displayed on a Fragment

∥☆過路亽.° 提交于 2019-12-04 17:48:18
问题 I have a problem in running a video in Samsung S3(Android 4.1.1), the issue seems to be because the videoview is on a fragment because if I put it on and activity, it works. Also I found out that if I turn on the GPU hardware acceleration on, the video works. I have also a game made by drawing on a SurfaceView and that view doesn't work as well(only with GPU on)... The rest of the app content is displayed as it supposed to (buttons and other layouts). I tested the app on Nexus S and on the

How can I move an image from one point to another using Android Canvas

我的梦境 提交于 2019-12-04 17:26:25
问题 I'm developing a game, and in this game I have to move an image on a Canvas from one point to another in any direction, not just vertical or horizontal. How can I move that image in this manner? 回答1: After getting a math lecture, it turns out that this is easy to solve. First, we need to get the angle which the target will be moving at. float deltaX = targetX - startX; float deltaY = targetY - startY; float angle = Math.atan2( deltaY, deltaX ); startX/Y can be current X/Y. Now that we have

How to create Bitmap form Drawable object

我是研究僧i 提交于 2019-12-04 17:07:47
I am developing custom view for android. For that I want give a user ability to select and image using just like when using ImageView In attr.xml I added bellow code. <declare-styleable name="DiagonalCut"> <attr name="altitude" format="dimension"/> <attr name="background_image" format="reference"/> </declare-styleable> In custom view I get this value as a Drawable which was provided in xml as app:background_image="@drawable/image" TypedArray typedArray = getContext().obtainStyledAttributes(arr, R.styleable.DiagonalCut); altitude = typedArray.getDimensionPixelSize(R.styleable.DiagonalCut

Draw From Old Canvas - Android

这一生的挚爱 提交于 2019-12-04 16:01:17
问题 I'm making an App that needs to be able to draw new graphics on top of the last set. This is my current onDraw() method - protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); if(points.size() > 0) { //do some stuff here - this is all working ok canvas.drawLine(p1.x, p1.y, p2.x, p2.y, linePaint); } } Basically, I need to draw the new graphics as a layer on top of the last, so what I'm looking for is a way to carry the image of the last canvas to the current. I have tried to

On Android how do I make oddly shaped clipping areas?

你。 提交于 2019-12-04 15:57:48
问题 Here is how to create a clipping area the shape of a circle: Path path = new Path(); path.addCircle(200,200,100,Direction.CW); c.clipPath(path); // c is a Canvas Now there's a clipping area on the Canvas which prevents drawing anything outside the bounds of that circle. But, what if I want to have the clipping area be shaped like a donut (or whatever)? I tried playing around with creating a second Path and using toggleInverseFillType on it and then adding that to the original path, but that

Relationship between Surface and Canvas: Android

为君一笑 提交于 2019-12-04 14:32:56
问题 What exactly is the relationship between a Surface and Canvas. Please explain. 回答1: A surface is a buffer. A Canvas holds the drawing. Views are not attached to the Canvas nor the Surface. The window is tied to a Surface and the ViewRoot asks the Surface for a Canvas that is then used by the Views to draw onto. For a detailled anwser, you can read this whole discussion, really interesting. 来源: https://stackoverflow.com/questions/3370212/relationship-between-surface-and-canvas-android

how to antialiasing in the canvas and path

為{幸葍}努か 提交于 2019-12-04 12:37:37
i meet a trouble when i use canvas.clipPath,it show sawtooth,it looks not smooth,i know if i used a Paint,i can use mPaint.setFlags(Paint.ANTI_ALIAS_FLAG) ,this can antialiasing ,but in my code ,i cannot use paint. public static void drawCurrentPageArea(Canvas canvas, Bitmap bitmap) { //cebakhja canvas.save(); canvas.clipPath(getPath5(), Region.Op.XOR); canvas.drawBitmap(bitmap, 0, 0, null); canvas.restore(); } public static Path getPath5() { Path mPath5 = new Path(); mPath5.moveTo(ptc.x, ptc.y); mPath5.quadTo(pte.x, pte.y, ptb.x,ptb.y); mPath5.lineTo(pta.x, pta.y); mPath5.lineTo(ptk.x, ptk.y)

Undo and redo in Canvas for Android

你说的曾经没有我的故事 提交于 2019-12-04 12:22:51
问题 I am using a customized version of FingerPaint for Android with some other features, like inserting images and moving them. I decided to implement an Undo&Redo, since it will make life just easier. In order to implement it, I finally decided to use a Stack where I push the Drawing Cache of the view, and from where I push the content every time I want to go back to a previous state. So, using the FingerPaint as a basis, I have the following: private void touch_up() { mPath.lineTo(mX, mY); //

Composite operations in Android Canvas

纵然是瞬间 提交于 2019-12-04 11:41:30
问题 I'm just starting with Android development and I'm coming from JavaScript/HTML world so I'm currently investigating the possibilities of the Android SDK. The HTML 5 canvas supports composite operations (See here). Is this possible in an Android Canvas? I scanned the API of the Canvas class but couldn't find anything useful. I need at least the composite operation "source-in" or (if this isn't possible) "source-atop". 回答1: Composition is handled by drawing on a Canvas with a Paint that uses a

Convert Text To Bitmap(Pixel) on Android

拈花ヽ惹草 提交于 2019-12-04 11:33:07
问题 I have an android application in which I need to download text from a website, convert it into bitmap format and display it on an LED-based display board. I am struggling with the bitmap conversion. Tried to use the following: Bitmap mybitmap = Bitmap.createBitmap(100, 16, Bitmap.Config.ALPHA_8); Canvas c = new Canvas(mybitmap); c.drawText("0", 0, 0, paint); But it doesn't seem to be working. Any suggestions? Update: Paint object is initialized like this: Paint paint = new Paint(); paint