android-canvas

How do I correctly translate pixel coordinates to canvas coordinates in Android?

末鹿安然 提交于 2019-12-22 04:10:34
问题 I am capturing a MotionEvent for a long click in an Android SurfaceView using a GestureListener . I then need to translate the coordinates of the MotionEvent to canvas coordinates, from which I can generate custom map coordinates (not Google Maps). From what I have read, I take that given MotionEvent e , e.getX() and e.getY() get pixel coordinates. How can I convert these coordinates to the SurfaceView 's canvas coordinates? Here is my GestureListener for listening for long clicks: /** *

Semi Circular Progress bar Android - drawing semi circle

筅森魡賤 提交于 2019-12-21 22:33:25
问题 I created a semi circular progress bar using this devadvance\circularSeekBar and it looks like this when I select that custom view from the palette. . In this I have two Relative layouts with weights. Weight of the layout containing the progress bar is 2 and the bottom one has weight of 3. And layout width and height of the progress bar is set to wrap content. So my issue is why does the progress bar look like this when selected from palette? Is it that the canvas size takes the perfect

How to draw a text inside a box on canvas with DynamicLayout and Ellipsize

纵饮孤独 提交于 2019-12-21 22:02:22
问题 I need to draw a text on canvas inside a specific box. I'm already using DynamicLayout to automatically calculate and break lines to fit inside the box width. Now I need to ellipsize the text automatically to fit the box height. How can I achieve this? It doesn't necessarily need to be by the height (pixels), it could be by the max number of lines. Example: "This is a sample text to fit inside the box" Actual Result: ------------ |This is a | |text to | |fit inside| ------------ the box

How to draw a text inside a box on canvas with DynamicLayout and Ellipsize

北城余情 提交于 2019-12-21 21:50:21
问题 I need to draw a text on canvas inside a specific box. I'm already using DynamicLayout to automatically calculate and break lines to fit inside the box width. Now I need to ellipsize the text automatically to fit the box height. How can I achieve this? It doesn't necessarily need to be by the height (pixels), it could be by the max number of lines. Example: "This is a sample text to fit inside the box" Actual Result: ------------ |This is a | |text to | |fit inside| ------------ the box

how to antialiasing in the canvas and path

青春壹個敷衍的年華 提交于 2019-12-21 18:28:54
问题 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

Android Scaling Canvas Bitmap

浪尽此生 提交于 2019-12-21 15:17:36
问题 I have a drawing app that allows the user to draw to a blank canvas. I am attempting to draw a scaled 'thumbnail' of the current bitmap so that when the user has scaled in the View, they can reference the thumbnail to get a sense as to where they are in the overall draw canvas. I have the scaling working, and am displaying the thumbnail in the correct location, but it appears that the thumbnail is not being updated on subsequent onDraws when new lines/shapes are added. So that I have access

Draw a text on a circle path in android

喜夏-厌秋 提交于 2019-12-21 14:58:28
问题 I need to draw a text on a circle path. I have tried the drawTextOnPath() method. But for texts like "fertile window" in the image attched, the text rotates and is not readable. Code I have used : customPath2.addArc(mCircleRectF, 30F, 64.28F); customPaint2.setAntiAlias(true); customPaint2.setDither(true); customPaint2.setStrokeWidth(mCircleStrokeWidth); customPaint2.setColor(Color.parseColor("#93BE66")); customPaint2.setStyle(Paint.Style.STROKE); customPaint2.setStrokeCap(Paint.Cap.ROUND);

Getting Bitmap from Custom SurfaceView

会有一股神秘感。 提交于 2019-12-21 09:14:48
问题 I have this code in a class that extends surface view and implements runnable I am able to use the class basically allows you to draw to the canvas using different colors and such. I'm trying to get a method that will allow me to save the image after it is drawn and this is the method. No matter what i do i just get a black image with nothing on it. Any ideas? I have cache drawing enabled Objective get a bitmap image from a custom SurfaceView I have exhausted options of looking at some other

Android canvas save always java.io.IOException: open failed: ENOENT (No such file or directory)

烈酒焚心 提交于 2019-12-21 08:18:09
问题 I have a canvas application. I'm trying to create a signature app with Canvas + onTouchListener . This is my save method, where I try to save the signature to an image: private void save() { hideMenuBar(); View content = this; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = content.getDrawingCache(); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); String imgPath = path+"/imotax/capture/spop/ttd

How to fill rectangle with opacity in android

喜夏-厌秋 提交于 2019-12-21 08:00:17
问题 I can fill rectangle with canvas draw rect: Rect rt = new Rect(0, 0, getWidth(), getHeight()); myPaint.setColor(myColor); myPaint.setStyle(Style.FILL); canvas.drawRect(rt, myPaint); But I need the method to fill rectangle with the opacity (in percent, with 0% is TRANSPARENT). How can I do that? 回答1: You can use the Alpha property of Paint class. myPaint.setAlpha(10); will help you. 来源: https://stackoverflow.com/questions/10348084/how-to-fill-rectangle-with-opacity-in-android