android-canvas

Adding multiple touch listeners inside canvas Android

让人想犯罪 __ 提交于 2019-12-25 08:15:46
问题 Suppose I have multiple drawings in my canvas, how can I add touch listener for each of the drawings seperately inside that canvas? I will be having different drawings like star, circle, rectangle etc etc added dynamically how can I handle each of them ? I couldn find ans in SO the very close question was this Set touch listeners on canvas drawings but it has no ans. Help and suggestions will be appreciated. Thanks in advance :) 回答1: Actually you can't add any touch listener on the drawings

How to rotate view by coordinate also in Android

本小妞迷上赌 提交于 2019-12-25 07:52:57
问题 first understand my question properly before voting, i have view that's like , <View android:id="@+id/View01" android:layout_width="280dp" android:layout_height="150dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="50dp" android:layout_marginTop="83dp" android:background="#212121" android:rotation="-5" android:visibility="visible" /> and output is, you can see that when i use android:rotation="-5" , it rotate views(black box) but their

android - animation by drawing bitmap is not smooth

我们两清 提交于 2019-12-25 07:48:18
问题 I am trying to animate several shapes(paths) by drawing them on the surface holders canvas. At first I was drawing them as paths and everything was fine, the movement was smooth. As I increased the number of objects(shapes) the performance decreased and I made some tests to see if instead of drawing shapes drawing bitmaps is faster. And.. drawing bitmaps seems to be considerable faster (less computation maybe) BUT the movement is not smooth. It looks like the bitmaps always move from pixel to

How to draw Bitmap from ARGB_8888 Bitmap

白昼怎懂夜的黑 提交于 2019-12-25 06:35:46
问题 I am drawing paths on canvas and creating Transparent bitmap while saving and creating cropping bitmap from transparent bitmap. See Images : In this I mage I am drawing path on canvas and I am creating transparent bitmap and according to startX,lowestY and highestX,highestY Bitmap cropBitmap =Bitmap.createBitmap(sourceBitmap,startX,lowestY,highestX,highestY); When I am cropping Bitmap I want Only "Test" drawing crop bitmap.But it's giving empty bitmap. Like this Inside red box I want cropped

Saving android canvas as a bitmap

*爱你&永不变心* 提交于 2019-12-25 06:27:58
问题 I want to save the canvas object in onDraw() method to be saved as a bitmap. Please do not suggest answers like "view.getDrawingCache(true)" .I want to save canvas directly to a bitmap 回答1: // first create a mutable bitmap - you determine the size bkg = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); // create a canvas with that empty bitmap Canvas c = new Canvas(bkg); // do whatever drawing methoods you need....I did a circle c.drawColor(mContext.getResources().getColor(R.color

Is it possible to add an array of images to canvas and then delete them?

我们两清 提交于 2019-12-25 03:37:17
问题 Is it possible to add an array of images to a canvas and then delete individual images?So lets say I declare an ArrayList and add my images to it. I then draw them on the canvas.How can i delete just one image instead of them all?Is this possible? ArrayList<Integer> myImageList = new ArrayList<Integer>(); myImageList.add(R.drawable.image1); myImageList.add(R.drawable.image2); myImageList.add(R.drawable.image3); canvas.drawBitmap(myImageList[0], 300, 400, null); canvas.drawBitmap(myImageList[1

Android SurfaceView not retaining previously drawn objects

混江龙づ霸主 提交于 2019-12-25 02:30:04
问题 I am experimenting with SurfaceView. My requirement is to simply render a node (simple drawable) first. Then, render more nodes at a later point in time . The snippets of my thread's run method & my doDraw method are below. I am just trying to render 2 different drawables in subsequent passes while retaining both. The problem is it wipes away whatever gets written in 1st pass (see comment in code). How to retain the previously drawn object? public void run() { Canvas canvas; while (_running)

SurfaceHolder.lockCanvas returns null if the surface is not in the foreground

那年仲夏 提交于 2019-12-25 02:21:58
问题 I'm currently doing a test with a LiveWallpaper in Android. I am drawing something on the canvas using code that looks something like this: final SurfaceHolder holder = getSurfaceHolder(); Canvas c = new Canvas(); c = holder.lockCanvas(); // c becomes null c.save(); c.drawBitmap(currentBitmap); c.restore(); holder.unlockCanvasAndPost(c); This part is working fine under normal circumstances . However, I have a listener that executes this code whenever a setting is changed in the Settings that

unable to add circles to canvas dynamically

你。 提交于 2019-12-25 02:03:19
问题 I tried to make a single ball bouncing to dynamic ball bouncing . Eg: here the number of circles is 50. But I am getting error while trying to make the circles dynamic (Model) .How do I make it work and make the model/circle dynamic.In this case 50 circles ? I really appreciate any help. Thanks in Advance. package com.stuffthathappens.games; import static android.hardware.SensorManager.DATA_X; import static android.hardware.SensorManager.DATA_Y; import static android.hardware.SensorManager

Setting the opacity of drawing canvas in android

◇◆丶佛笑我妖孽 提交于 2019-12-25 01:55:58
问题 I am working on a function that drawing some transparent line on the canvas, the problem is , there is some "ball shape" on the line as the screenshot show. Here is my code: canvas = new Canvas(alteredBitmap); paint = new Paint(); paint.setAntiAlias(true); paint.setStrokeWidth(width); paint.setColor(color); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeCap(Paint.Cap.ROUND); paint.setAlpha(alpha); matrix_draw = new Matrix(); canvas.drawBitmap(bmp,