android-canvas

SurfaceView, draw image and reduce size, rotate image

≯℡__Kan透↙ 提交于 2020-01-14 07:00:47
问题 I wan to draw a image (get from camera) on surfaceview. After drawing the image i want to reduce the size of the image, change the image location on surface view with touch. rotate the image. currently i draw the image on surface view but how the remaining task is not done. Please some body help me. Thanks 回答1: public void drawImage(Canvas canvas, Bitmap bitmap, int x, int y, int rotationAngle, float scalingfactor){ Matrix matrix = new Matrix(); matrix.postRotate(rotationAngle, bitmap

SurfaceView, draw image and reduce size, rotate image

﹥>﹥吖頭↗ 提交于 2020-01-14 07:00:17
问题 I wan to draw a image (get from camera) on surfaceview. After drawing the image i want to reduce the size of the image, change the image location on surface view with touch. rotate the image. currently i draw the image on surface view but how the remaining task is not done. Please some body help me. Thanks 回答1: public void drawImage(Canvas canvas, Bitmap bitmap, int x, int y, int rotationAngle, float scalingfactor){ Matrix matrix = new Matrix(); matrix.postRotate(rotationAngle, bitmap

Object following custom path

感情迁移 提交于 2020-01-14 04:05:00
问题 I'm working on 2d game dev project. It's some kind of board game. As background I have board game with path, that isn't real circle, but some kind of wavy line. Objects are moving across that path. On touch event...I need to my player's object get at that exact position, but they need to follow that path. How to translate (draw) objects over some custom path? 回答1: You could draw your path (i.e. your wavy line) using an actual Path object onto the Canvas , and then use PathMeasure to calculate

Find exact coordinates of a single Character inside a TextView

独自空忆成欢 提交于 2020-01-12 14:23:29
问题 Currently I'm using paintObject.measureText(textCopy.substring(0,i)) while iterating through a copy of the TextView's text. For example, measureText("abc".substring(0,1)) will give me the relative x coordinates of 'b'. The y coordinate I get from layout.getLineTop() . This is working but not accurate for x coordinates for non-monospaced fonts. I can calibrate a little, but on each device it works differently. The best solution I can think of is to overwrite the class that is responsible for

How to rotate TextView without clipping its bounds?

拈花ヽ惹草 提交于 2020-01-12 05:04:27
问题 I'm trying to rotate my subclass of TextView using canvas.rotate() : canvas.save(); final int w = getWidth(); final int h = getHeight(); float px = w/2f; float py = h/2f; canvas.rotate(mAngle, px, py); super.draw(canvas); canvas.restore(); TextView is rotated, however bounds of my view are clipped: I understand that this is because of my view's size - it is not changed during rotation while it should. But if I'll change width\height in onMeasure problem will remain - I'm using LayoutParams

canvas is offset by setting identity matrix in onDraw of custom view

人走茶凉 提交于 2020-01-11 07:18:34
问题 I set a matrix to my canvas in the onDraw method of a custom view via canvas.setMatrix(matrix); then I just draw a grid using predefined paints: canvas.drawRect(0,0,viewWidth,viewHeight, background); for(int i=0; i <= nRows; i++){ canvas.drawLine(0,i*cellHeight, nCols*cellWidth,i*cellHeight,lines); canvas.drawLine(i*cellWidth, 0, i*cellWidth, nRows*cellHeight, lines); if(i != nRows) canvas.drawText(""+i, i*cellWidth, (i+1)*cellHeight, text); } and for some reason the whole canvas is offset by

Android - Draw Bitmap within Canvas

别来无恙 提交于 2020-01-09 10:13:43
问题 I currently have a maze game which draws a 5 x 5 square (takes the width of screen and splits it evenly). Then for each of these boxes using x and y cordinates I user drawRect, to draw a colored background. The issue I am having is I now need to draw an image within this same location, therefore replacing the current plain background colour fill. Here is the code I am currently using to drawRect (a few example): // these are all the variation of drawRect that I use canvas.drawRect(x, y, (x +

Android - Draw Bitmap within Canvas

做~自己de王妃 提交于 2020-01-09 10:11:50
问题 I currently have a maze game which draws a 5 x 5 square (takes the width of screen and splits it evenly). Then for each of these boxes using x and y cordinates I user drawRect, to draw a colored background. The issue I am having is I now need to draw an image within this same location, therefore replacing the current plain background colour fill. Here is the code I am currently using to drawRect (a few example): // these are all the variation of drawRect that I use canvas.drawRect(x, y, (x +

Measuring text height to be drawn on Canvas ( Android )

人盡茶涼 提交于 2020-01-08 13:25:54
问题 Any straight forward way to measure the height of text? The way I am doing it now is by using Paint's measureText() to get the width, then by trial and error finding a value to get an approximate height. I've also been messing around with FontMetrics , but all these seem like approximate methods that suck. I am trying to scale things for different resolutions. I can do it, but I end up with incredibly verbose code with lots of calculations to determine relative sizes. I hate it! There has to

How to centerCrop an image Programatically by maintaining Aspect ratio like centerCrop do in XML?

六月ゝ 毕业季﹏ 提交于 2020-01-07 08:47:11
问题 How to centerCrop an image like the same method "centerCrop" do in xml android ? I don't want to crop the center of the image .I have tried the below code but ,it was cropping the center portion of the image,and it produce a square shaped image,I want the same centerCrop function to use in a Canvas on android.Can anyone help?? Hope my question is clear to you. Bitmap bitmap=BitmapFactory.decodeResource(res, (R.drawable.ice)); Bitmap cropBmp; if (bitmap.getWidth() >= bitmap.getHeight()){