android-canvas

[android]Circle with SweepGradient to animate

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:14:06
Hi, I m trying to draw a circle as shown in the picture.where my values ranges from 0-100. 0-40 green 41-60 yellow 61-80 orange and 81-100 red. the view should animate from 0 to defined value slowly,this one to achieve. I have tried the following code ,and trying to achieve, code as follows: public class GradiantActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new GradientTestView(this)); } private class GradientTestView extends View { private Paint mPaint

onScale and Canvas - how to adjust origin point after zooming image?

风流意气都作罢 提交于 2019-12-03 16:09:04
I have a very simple test app with a custom component MyView.java - which displays a scrollable and scalable image (representing a board in a Scrabble-like word game): 1) In my scale listener I adjust the scale factor: public boolean onScale(ScaleGestureDetector detector) { mScale *= detector.getScaleFactor(); // XXX how to adjust mOffsetX and mOffsetY ? XXX constrainZoom(); constrainOffsets(); invalidate(); return true; } 2) And then in the drawing method of my custom component I apply the translation and scale factor: protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas

Android: Drawing an arc inside a circle

泄露秘密 提交于 2019-12-03 15:52:37
I'm trying to draw an arc inside a circle to represent the temperature, but I'm having a difficult time achieving that. During my search I found those solutions This one I couldn't understand what is the scale method for, and is drawing more than one arch, which confused me a bit This post gave it a fixed size where I need the size to be controlled by the custom view in my XML layout From here I understood the concept the degrees but I didn't understand how to determine the oval size What i reached so far @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int startTop = 0;

Android - plotting gps coordinate on custom map

巧了我就是萌 提交于 2019-12-03 15:08:22
I have an activity in my app where there are images I use as maps. If the image is "grid aligned" to google maps then when I use the top left and bottom right corners of the map I get from googlemaps online then I can turn the users gps into an x and y on screen. However if the map is not "grid aligned" and is at an angle than the values my math returns draws the users position off screen. Obviously I am missing the part on how to handle the angle of the map so if anyone could shed some light on how to do that it would be super helpfull. I know I would have to figure out the angle in radians

Android canvas fill background color (Canvas application)

三世轮回 提交于 2019-12-03 14:39:26
By having the following codes, I have some questions. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( new View(this) { Paint mPaint = new Paint(); @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); int width = this.getWidth(); int height = this.getHeight(); int radius = width > height ? height/2 : width/2; int center_x = width/2; int center_y = height/2; // prepare a paint mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(5

How to save view from canvas to PNG file?

北慕城南 提交于 2019-12-03 13:47:33
I created canvas that can be used to draw some shapes on it. How can I save its content to PNG file on user's SD card? G_S check out this link this link In this link you can find the method void saveImage() { try { String filename = Environment.getExternalStorageDirectory().toString(); File f = new File(filename ,"myImage.png"); f.createNewFile(); System.out.println("file created " + f.toString()); FileOutputStream out = new FileOutputStream(f); Bitmap bitmap = showImage(urlStr); bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); } catch (Exception e) { e.printStackTrace(); } } which is used

How to drawing a path with a bitmap?

戏子无情 提交于 2019-12-03 13:38:26
I have a little drawing app and want to use "complex" shapes as brushes, i.e. a star. Drawing with a simple brush already works with this code: remotePath.reset(); remotePath.moveTo(start_x, start_y); float dx = Math.abs(end_x - start_x); float dy = Math.abs(end_y - start_y); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { remotePath.quadTo(start_x, start_y, (end_x + start_x) / 2, (end_y + start_y) / 2); } remotePath.lineTo(end_x, end_y); // commit the path to our offscreen mCanvas.drawPath(remotePath, remotePaint); // kill this so we don't double draw remotePath.reset(); invalidate(); I

Redraw multiple Paths at same positions from previous layout orientation

大城市里の小女人 提交于 2019-12-03 13:10:01
Based on my previous question of " How to create a BottomBar as StickyBottomCaptureLayout in camera2 Android api? ", I created a layout with a StickyBar (SB) which is always locked above/near the system bar. I set the default positions and coordinates of the SB and the other layout in onLayout() (exactly as my answer ). The upper layout is a simple custom DrawView which has an ArrayList of Path s drew by the user. When the device rotates, it recalls onDraw() and calls several times canvas.drawPath() . However, the Path s are redrew with the same coordinates as before but on a different

Canvas.drawText() doesn't render large emojis on Android

断了今生、忘了曾经 提交于 2019-12-03 12:58:38
Canvas.drawText() doesn't render emojis above a certain font size on Android. Correct render at somewhere below 256 px: Incorrect render at above 256 px: (There is a similar question about Google Chrome, and just like Android, Chrome also uses the Skia graphics library, so this seems like a bug in Skia .) Apparently emojis fail to render above 256 px font size on my devices. But I'm not sure if this is the limit everywhere. Is there a way to learn the font size at which emojis disappear? Or is there a workaround for this? I've come up with a test (an empirical estimation) for the maximum font

Android App - How to save a bitmap drawing on canvas as image? Check code?

夙愿已清 提交于 2019-12-03 12:20:36
问题 I tried to use the following codes to Draw on canvas Save the canvas on Image Problem - When I try to save the image, it shows a null pointer error and nothing is saved. Please help me to find the problem with the code or suggest me an alternative, which does excatly the same. Thanks in advance. Code to draw on canvas: package com.example.draw2; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android