android-canvas

convert view into bitmap [duplicate]

两盒软妹~` 提交于 2019-11-27 01:29:56
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Converting a view to Bitmap without displaying it in Android? I am trying to convert the view into bitmap from following reference link link text Now the problem is how can i get the bitmap that is being converted from view only. in the example author has used relativelayout.dispatchDraw(c) but this line is giving me compile time error i.e. The method dispatchDraw(Canvas) from the type ViewGroup is not visible

Drawing a filled rectangle with a border in android

自作多情 提交于 2019-11-27 01:27:08
问题 Is there any way in Android to draw a filled rectangle with say a black border. My problem is that the canvas.draw() takes one paint object, and to my knowledge the paint object can't have a different color for the fill and the stroke. Is there a way around this? 回答1: You draw a rectangle with the color of the border and the size of the rectangle plus the border, you change the color of the paint and draw again the rectangle with the normal size. 回答2: Try paint. setStyle (Paint.Style. FILL )

How to draw a path on an Android canvas with animation?

爷,独闯天下 提交于 2019-11-27 00:27:56
问题 I'm making an Android app and I've got a tricky thing to do. I need to draw a path on a canvas but the drawing should be animated (ie. drawing point after point with a slight delay). Is it possible to make something like this using Android SDK? If not, how could I produce this effect? 回答1: Try this code, I used it to draw a heartbeat using Path & Canvas : public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle

creating an empty bitmap and drawing though canvas in android

徘徊边缘 提交于 2019-11-27 00:16:02
I'd like to create an empty bitmap and set canvas to that bitmap and then draw any shape on bitmap. bigstones This is probably simpler than you're thinking: int w = WIDTH_PX, h = HEIGHT_PX; Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap Canvas canvas = new Canvas(bmp); // ready to draw on that bitmap through that canvas Here's a series of tutorials I've found on the topic: Drawing with Canvas Series Do not use Bitmap.Config.ARGB_8888 Instead use int w = WIDTH_PX, h = HEIGHT_PX; Bitmap.Config

SurfaceView flashes black on load

风格不统一 提交于 2019-11-26 23:53:14
I have a drawing app that takes about 2-5 seconds to load the drawing for complicated drawings (done via an AsyncTask ). For a better user experience, during this time I flash the stored PNG version of the drawing I have from the app directory as an ImageView , and show a loading ProgressBar calling setContentView() in the Activity constructor: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/flash" android:layout_width="match

Loading a resource to a mutable bitmap

允我心安 提交于 2019-11-26 22:53:36
问题 I am loading a bitmap from a resource like so: Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image); What I want to do is make some changes to the bitmap before It gets drawn to the main canvas in my draw method (As it would seem wasteful to repeat lots of drawing in my main loop when it isn't going to change). I am making the changes to the bitmap with the following: Canvas c = new Canvas(mBackground); c.drawARGB(...); // etc So naturally I get an exception java.lang

How to Measure TextView Height Based on Device Width and Font Size?

99封情书 提交于 2019-11-26 22:23:40
I am looking for method in Android that will take a input (text, text_font_size, device_width) and based on these calculations it will return how much height will required to display particular text ? I am setting a text view/ webview height runtime based on his content,I am aware about warp content but I can't use in my case because of some web view minimum height issue. So I am trying to calculate height and based on that I am setting view height. I have tried with following ways Paint paint = new Paint(); paint.setTextSize(text.length()); Rect bounds = new Rect(); paint.getTextBounds(text,

Drawable image on a canvas

被刻印的时光 ゝ 提交于 2019-11-26 21:53:19
How can I get an image to the canvas in order to draw on that image? The good way to draw a Drawable on a canvas is not decoding it yourself but leaving it to the system to do so: Drawable d = getResources().getDrawable(R.drawable.foobar, null); d.setBounds(left, top, right, bottom); d.draw(canvas); This will work with all kinds of drawables, not only bitmaps. And it also means that you can re-use that same drawable again if only the size changes. You need to load your image as bitmap: Resources res = getResources(); Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.your_image);

How to draw Arc between two points on the Canvas?

泪湿孤枕 提交于 2019-11-26 21:43:16
I have two points in the canvas, now I'm able to draw a line between those points like this below image by using This code canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint); I want to draw the arc between two points like below image. How can I draw like this. Finally I got the solution from this code: float radius = 20; final RectF oval = new RectF(); oval.set(point1.x - radius, point1.y - radius, point1.x + radius, point1.y+ radius); Path myPath = new Path(); myPath.arcTo(oval, startAngle, -(float) sweepAngle, true); To calculate startAngle , use this code: int startAngle = (int) (180 / Math.PI

Android: How to detect when a scroll has ended

送分小仙女□ 提交于 2019-11-26 21:29:21
I am using the onScroll method of GestureDetector.SimpleOnGestureListener to scroll a large bitmap on a canvas. When the scroll has ended I want to redraw the bitmap in case the user wants to scroll further ... off the edge of the bitmap, but I can't see how to detect when the scroll has ended (the user has lifted his finger from the screen). e2.getAction() always seems to return the value 2 so that is no help. e2.getPressure seems to return fairly constant values (around 0.25) until the final onScroll call when the pressure seems to fall to about 0.13. I suppose I could detect this reduction