android-canvas

Simple thread issue with Android animation

徘徊边缘 提交于 2019-12-01 06:34:54
I'm trying to implement a thread with some simple Android animation. I'm just getting an error with sleep() - It says I need a method for it. I know there is probably an obvious solution. My app just places a ball that moves in a circle at a random location. What I want is to continue placing shapes at random locations. Anyway, can someone please tell what I'm doing wrong with my thread? Thanks. public class DrawingTheBall extends View { Bitmap bball; Random randX, randY; double theta; Handler m_handler; Runnable m_handlerTask; //for some reason I get a syntax error here m_handler = new

Understanding Android Canvas Clipping

与世无争的帅哥 提交于 2019-12-01 05:44:24
I am having trouble finding an answer to this. Consider the clipping code below: boolean is_ok = mycanvas.clipRect(clip_left, clip_top, clip_right+1, clip_bottom+1); mycanvas.getClipBounds(clipRect); if (!is_ok || clipRect.left != clip_left || clipRect.top != clip_top || clipRect.right != clip_right+1 || clipRect.bottom != clip_bottom+1) { Log.i("DEBUG", "setClipping failed"); } When the clip bounds are returned they don't match what was just set. For example if clip_left, clip_top, clip_right, clip_bottom are (100,50,109, 59) then I would expect the clipping bounds to be (100, 50, 110, 60)

How to draw a bitmap on a canvas, respecting alpha values of the bitmap?

送分小仙女□ 提交于 2019-12-01 05:24:59
问题 background i have a master bitmap that i need to draw on it other bitmaps. the master bitmap has some semi-transparent pixels (pixels with variant values for the alpha channel) , so that the other bitmaps that are drawn on it should be merged with it instead of overriding the colors completely. the question how can i set the canvas to draw the bitmaps on the master bitmap with respect to the semi-transparent pixels ? note: the alpha is not for the whole bitmap/s . it's per pixel. 回答1: Canvas

Android get Bitmap Rect (left, top, right, bottom) on a Canvas

感情迁移 提交于 2019-12-01 05:10:59
问题 I am drawing a Bitmap over a Canvas and then doing some scaling on it, pretty simple, just using canvas.scale(int, int, pivot, pivot), and then, after the scaling is completed, I need to get the Bitmap's coordinates relative to the viewport. Is there any convenient way to do this without calculating by myself what the initial position is then where it went after the scale? Actually, the Bitmap with the scaling can get bigger than the Canvas, so I need actually the clip size of the view and

Draw bitmaps from resources over another

Deadly 提交于 2019-12-01 04:47:22
I have got two bitmaps, background and foreground . How do I draw bitmap foreground on background without using another Canvas? Solution: 1) First create bitmaps from resources with additional option ARGB_8888 BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; 2) Declare bitmaps Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background, options); Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.foreground, options); 3) Inside onDraw() function draw graphics protected void

Draw background of custom View from .png file on Android

你离开我真会死。 提交于 2019-12-01 04:00:10
问题 I created a custom View by extending from View. In onDraw() I managed to draw some circles and other stuff. But now I want to add a background from a resource (sd card or a stream) which is actually a map I download from our server and than draw on it. It's for Android 8+ @Override protected void onDraw(Canvas canvas) { Canvas g = canvas; String file = "/mnt/sdcard/download/tux.png"; Bitmap bg = null; try { bg = BitmapFactory.decodeFile(file); g.setBitmap(bg); } catch (Exception e) { Log.d(

Draw bitmaps from resources over another

亡梦爱人 提交于 2019-12-01 03:24:45
问题 I have got two bitmaps, background and foreground . How do I draw bitmap foreground on background without using another Canvas? Solution: 1) First create bitmaps from resources with additional option ARGB_8888 BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; 2) Declare bitmaps Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background, options); Bitmap foreground = BitmapFactory.decodeResource

Canvas does not draw in Custom View

*爱你&永不变心* 提交于 2019-12-01 02:59:18
I created a Custom View CircleView like this: public class CircleView extends LinearLayout { Paint paint1; public CircleView(Context context) { super(context); init(); } public CircleView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public void init() { paint1 = new Paint(); paint1.setColor(Color.RED); } protected void onDraw(Canvas canvas) { //super.onDraw(canvas); canvas.drawCircle(50, 50, 25, paint1); this.draw(canvas); } } Then I included it on my Activity's layout root <RelativeLayout> : <com.turkidroid.test.CircleView android:id="@+id/circle_view" android

How to get the size of the screen size in a canvas in android?

女生的网名这么多〃 提交于 2019-12-01 00:52:52
I am able to get the screen size in the normal activity but I need to get the screen size in a canvas view & manipulate in accordance with it.Any snippet on it will be helpful.Thanks. i got widthPixels heightPixels use ing this. DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics(); int w = metrics.widthPixels; int h = metrics.heightPixels; 来源: https://stackoverflow.com/questions/9124797/how-to-get-the-size-of-the-screen-size-in-a-canvas-in-android

android canvas draw circles and get touch events

心已入冬 提交于 2019-12-01 00:36:39
i have been trying to make such a demo where i need to draw many(hundreds of) circle shapes on canvas (or any other way if possible) , after drawing the canvas i need to zoom and move it .. and also want to capture the click(touch) event of each shape separately .. so i know i can get canvas touch event and get x and y positions and check which which circle is touched but i have to draw many circles and as well after zooming and moving the circle's x and y pos is changes so plz help me.. Give me any suggestion how to do this..the way to go.. or if any ANDROID MASTER have done some thing like