android-canvas

Android - concurrent access to the canvas safely?

一世执手 提交于 2019-12-12 03:40:56
问题 I'm making a grid + tile activity where tiles need to move across the grid. The grid (and tiles) are being drawn on a surfaceView in a separate thread to the UI (UI deals with touch events and pushes them onto a queue for the grid to process). This is all fine. I have a toolbar from which I can drag tiles. The toolbar is a View which has been added to the relative layout (and runs on the UI thread). No matter how many times i use synchronize or try to safeguard the canvas from being written

Algorithms used in android.graphics.Canvas

自古美人都是妖i 提交于 2019-12-12 03:15:48
问题 I am trying to find out what drawing algorithms android.graphics.Canvas is using, and especialy for drawLine and drawCircle . I have managed to find Canvas_Delegate.java, but I cannot understand which algorithm is used in each occasion. Any idea? 回答1: Summarizing the comments: There are at least two implementations of the drawing functions, one purely in software (the Skia library), and one that uses the GPU when hardware acceleration is enabled. The Skia implementation is written in C++, not

Android - Setting background on canvas using PNG file

半世苍凉 提交于 2019-12-12 02:54:40
问题 I'm trying to set a .PNG file as background on Canvas in my app. I've made an image 480 x 800 and used this method: canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.image_1), 0, 0, null); I've started an emulator (WVGA800) but my image looks greater than screen of the device. How do I resize this image or what kind of methods should I use to make this image well-matched. Secondly, is there any way to make backgrounds like this universal for devices with different

Image overlays and hot regions in android

不羁的心 提交于 2019-12-12 02:44:49
问题 I am writing an activity where there is a picture that is hidden by some other picture that is broken to active slices. You will be able to click each slice and perform some action. When this action is successfull the overlay slice disappears and a part of original image is displayed. The game finishes when you uncover complete image. Imagine Mahjongg with the floor level. You can click a tile and if it matches another selected tile the background under the tile is displayed. My task is

How to insert an image with canvas?

那年仲夏 提交于 2019-12-12 02:00:01
问题 I´m trying to insert a simple image with canvas in Android with the next code, but when i try to execute in the smartphone, only appears a white screen without image. import android.support.v7.app.ActionBarActivity; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; public class MainActivity extends ActionBarActivity { @Override protected void

Andorid DrawPath doesn't fill-up the enclosed area

為{幸葍}努か 提交于 2019-12-12 01:45:20
问题 Following list shows the x,y coordinates and particular method used to create a Path. 0 0 moveTO 180 0 lineTo 180 0 moveTO 246 227, 127 24, 115 150 cubicTo 127 276, 246 71, 180 300 cubicTo 180 300 moveTO 44 261, 166 332, 90 339 cubicTo 14 332, 136 261, 0 300 cubicTo 0 300 moveTO 0 0 lineTo Raw data points x = [0, 180, 180, 246, 127, 115, 127, 246, 180, 180, 44, 166, 90, 14, 136, 0, 0, 0] y = [0, 0, 0, 227, 24, 150, 276, 71, 300, 300, 261, 332, 339, 332, 261, 300, 300, 0] Idea of this algo is

Smooth endles scrolling background with canvas?

*爱你&永不变心* 提交于 2019-12-11 23:45:14
问题 Welcome all I have a background image and what I want is for it to be moving slowly to the right and when the image has reach the right end of the screen with the end of the left starting side of the image, the image must start again showing the start of the right side, as an infinite horizontal scroll. How can this be achieved without generating bitmap overflow memory exceptions? I tryed it drawing two times the bitmap with canvas... but it is not smooth, it is very creepy with jumps and not

How to Draw Arrowline in android.graphics.Path with correct configerations

醉酒当歌 提交于 2019-12-11 22:21:58
问题 What I have Tried: I'm trying to display the arrow line with following code Path mArrowPath=new Paint();; mArrowPath.rewind(); mArrowPath.moveTo(0, mHeight / 2); mArrowPath.lineTo(mWidth / 2, 0); mArrowPath.lineTo(mWidth, mHeight / 2); mArrowPath.lineTo(mWidth * 3 / 4, mHeight / 2); mArrowPath.lineTo(mWidth * 3 / 4, mHeight); mArrowPath.lineTo(mWidth / 4, mHeight); mArrowPath.lineTo(mWidth / 4, mHeight / 2); mArrowPath.lineTo(0, mHeight / 2); Shape pathshap = new PathShape(mArrowP,maxWidth

Android: custom draw on an given image (with SurfaceView)

我怕爱的太早我们不能终老 提交于 2019-12-11 21:13:09
问题 I am trying to load an image to SurfaceView, and draw some scratch upon this image. To to that, I have create an custom SurfaceView, MySurfaceView, with the following functions: public MySurfaceView(Context context, AttributeSet attrs) { super(context, attrs); mHolder = getHolder(); mHolder.addCallback(this); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(3); mPaint.setColor(Color.WHITE); setWillNotDraw(false); } public void setImageBitmap(Bitmap bitmap) { mBitmap = bitmap; }

Trying to get the x, y coordinate of each random circle that is drawn in android [duplicate]

给你一囗甜甜゛ 提交于 2019-12-11 21:09:35
问题 This question already has answers here : Trying to get the x, y coordinate of each random circle that is drawn on the screen (2 answers) Closed 4 years ago . I am making a game that will create random circles on the screen. The circles created randomly will have the value red or green. My question is that I would like to be able to not only determine when a user clicks on one of the circles but determine what circle they have ultimately clicked on (red or green). My main problem is trying to