android-canvas

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

喜你入骨 提交于 2019-12-03 02:54:56
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.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; import android.view

Drag and move a circle drawn on canvas

荒凉一梦 提交于 2019-12-03 02:52:08
问题 I am working on an Android application which should allow user to draw a circle on canvas and drag it . I have been able to draw lines and circles on it.But I cant seem to be able to drag it. Is it possible to drag an object drawn on canvas in Android?.For example if I detect a touch within the circle, how do I delete the circle from a previous position and move it to the current position? I have tried invalidate() .But it wont work if the user has drawn multiple circle and wants to move all

draw rounded edge arc in android with embossed effect

左心房为你撑大大i 提交于 2019-12-03 02:46:29
问题 I am trying to develop a custom component i.e. arc slider, I am done with the arc and the thumb but not able to figure out how can I draw the rounded edge arc and also the embossed effect in it. at the moment the slider looks something like this the code for drawing the arc is private void drawSlider(Canvas canvas) { float sweepDegrees = (value * arcWidthInAngle) / (maximumValue - minimumValue); // the grey empty part of the circle drawArc(canvas, startAngle, arcWidthInAngle, mTrackColor); //

How to properly scale a game on Android

不想你离开。 提交于 2019-12-03 01:15:15
for the sake of simplicity let's assume that I'm making a simple Pong clone game for Android. Let's assume that it would only be playable in the landscape mode. (ignore square phones for now). I'd like the game to look in the same scale on each phone, to the extent that if you took a screenshot of the game on QVGA phone, and resized the screenshot to WVGA size, it would look almost the same as would the game look on WVGA phone. In other words, the paddle's width should always be 1/32 of the screen width, the ball's diameter should always be 1/16 of the screen width. What would be the proper

Canvas.drawArc() artefacts

青春壹個敷衍的年華 提交于 2019-12-03 00:16:20
I draw an arc on canvas in a custom view as shown below. Paint and rectangle are defined outside of onDraw() and added in there for simplicity purpose. protected void onDraw(Canvas canvas) { super.onDraw(canvas); RectF rectangle = new RectF(60f, 60f, 480f, 480f); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(0x40000000); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(120); canvas.drawArc(rectangle, 225f, 315f, false, paint); } When I run this code on Galaxy Nexus with 4.3, there are following artefacts. There is no such artefacts when running on Nexus 5 with 4.4

How to apply dynamic alpha mask to a Text on Android

ε祈祈猫儿з 提交于 2019-12-03 00:02:17
I want to make a dynamic alpha mask with drawable shapes as circles or whatever, and apply it to a drawed text on Android. Here is an example of what i want : I am trying to make it with setXfermode(new PorterDuffXfermode(Mode.SRC_IN)) , but i can't get it work. Here is the code I have in onDraw(Canvas canvas) method : Paint paint = new Paint(); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.WHITE); canvas.drawCircle(50, 50, 50, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); paint.setColor(Color.RED); canvas.drawText("hello", 0, 50, paint); Thanks

Save canvas then restore, why is that?

空扰寡人 提交于 2019-12-02 23:39:10
I often see the following code canvas.save(). canvas translate or rotate some drawing canvas.restore I don't understand why we save and then restore. What's the point of undoing what we just did! I am sure I am missing something here Thanks I understand this question is a bit dated, but for anyone still looking for an answer I can ELI5; Imagine the canvas is a piece of paper, and you're tasked with drawing a picture of a robot right side up, at the bottom, and another robot upside down, slightly moved to the right, and about 40% smaller at the top. Something like this; How would you start?

Custom Brush with Undo/Redo operation in Android Canvas

笑着哭i 提交于 2019-12-02 23:17:16
问题 I want to implement a canvas drawing application with custom brush & undo/redo operation. First of all my code works perfectly without using the custom brush (including the undo/redo operation). According to this answer How to make custom brush for canvas in android? I used simple image spikes for bitmap draw. Now the issue are, The undo, redo operation doesn't works, custom brush paints over and over again whenever moving the touch points. Q: How to make the undo/redo operation work? The

How to magnify/zoom part of image

给你一囗甜甜゛ 提交于 2019-12-02 23:12:08
I'm making an app where user will be able to click on part of the image and get a magnified version in the corner of WebView . I managed to make a Paint that would make a zoom version, but it displays wrong location, like there's some offset. I know this question has been asked a lot of times and was already answered, but it appears non of those solutions helped. Here's code I've used: @Override public boolean onTouchEvent(@NonNull MotionEvent event) { zoomPos = new PointF(); zoomPos.x = event.getX(); zoomPos.y = event.getY(); matrix = new Matrix(); mShader = new BitmapShader(MainActivity

Draw bubble programmatically

白昼怎懂夜的黑 提交于 2019-12-02 22:52:33
I would like to have a bubble with a precentage value in my app, I can't use 9 patches as i want it to be customizable and its background color should be changeble. It should look something like this How can I do it? This bubble will have views inflated inside of it, like this percentage or some larger layouts. Also depending on the layout(phone or tablet) it might have one side larger than the other (arrow not at the center) so that's another reason i prefer doing it programmatically Create a custom Drawable and use it for the background of whatever container you are putting your text or