android-canvas

Draw a Bitmap in Arc center?

泄露秘密 提交于 2019-12-10 10:24:09
问题 In my Custom View, I draw multiple filled Arc s like this: canvas.drawArc(oval, startAngle, sweepAngle, true, sectorPaint); Now, I want to draw an icon on the center of the Arc. I started with this: Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_icon); canvas.drawBitmap(bitmap, pointX, pointY, null); //pointX & pointY ?? However, I don't know what should I set for pointX and pointY . Here is the data I have: Oval center coordinates and radius. startAngle and

How to move multiple bitmaps in single canvas android

僤鯓⒐⒋嵵緔 提交于 2019-12-10 06:08:21
问题 I want to move multiple bitmap on the same canvas. Using below code i can move one bitmap when touch on the screen but, i can't identify the touch event on the bitmap so that i couldn't move specific bitmap. public class DrawTopologyView extends View { Paint paint = new Paint(); Bitmap zed_bitMap, lamp_on_bitmap, fan_on_bitmap, ac_on_bitmap; int START_X = 5; int START_Y = 5; float x = 500-24,y=START_Y; public DrawTopologyView(Context context) { super(context); zed_bitMap = BitmapFactory

Android canvas change background color

与世无争的帅哥 提交于 2019-12-10 02:51:55
问题 Android canvas change color I have an app with two views <com.myexample.ui.view.BackgroundView android:id="@+id/id_draw_canvas_classroom" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="3dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="3dp" android:layout_weight="1" android:background="#FFFFFFFF" /> <com.myexample.ui.view.FrontView android:id="@+id/id_draw_canvas_user" android:layout_width="fill

Camera onPreviewFrame not called on some devices

别说谁变了你拦得住时间么 提交于 2019-12-09 16:49:25
问题 I am expecting the LogCat to be logging #onPreviewFrame() multiple times, but it only works on selected devices like: Samsung Galaxy S6 (7.0) Samsung Galaxy S6 (6.0.1) LG Leon (5.0.1) But does not on the following devices: LG G4 (6.0) Huawei 6X (7.0) Nexus 6P (7.0) Below is the code snippet: public CameraSurfaceView(Context context, AttributeSet set) { super(context, set); Log.d(TAG, "CameraSurfaceView(context, set)"); // Get the Surface Holder this.holder = this.getHolder(); this.holder

Getting Bitmap from WebView generates OutOfMemory crash

旧时模样 提交于 2019-12-09 14:32:49
问题 I have a custom WebView and I want to get a bitmap of its content (offscreen included). I used this code, which I got from here: public static Bitmap getBitmapFromWebviewV2(WebView webView) { webView.measure(View.MeasureSpec.makeMeasureSpec( View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight()); webView.setDrawingCacheEnabled(true); webView

Android: Drawing an arc inside a circle

本秂侑毒 提交于 2019-12-09 12:53:58
问题 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

Using canvas and bitmap in Android , how to get this image?

微笑、不失礼 提交于 2019-12-09 10:38:02
问题 I am new in android. I am trying to draw this image(match statistic) and fill the image with color with 10% to 100% . I tried this much and this is image this is the code public class DrawView extends View { Paint paint = new Paint(); public DrawView(Context context) { super(context); } @Override public void onDraw(Canvas canvas) { paint.setColor(Color.BLACK); paint.setStrokeWidth(3); canvas.drawRect(30, 30, 100, 100, paint); paint.setStrokeWidth(0); paint.setColor(Color.GRAY); canvas

Why canvas is not the same size as view in onDraw? (Android)

梦想与她 提交于 2019-12-09 09:48:12
问题 I tried with this @Override protected void onDraw(Canvas canvas) { Log.e("TEST", "canvas width: " + canvas.getWidth() + ""); Log.e("TEST", "view width: " + this.getWidth() + ""); Log.e("TEST", "canvas height: " + canvas.getHeight() + ""); Log.e("TEST", "view height: " + this.getHeight() + ""); super.onDraw(canvas); Log.e("TEST", "canvas width: " + canvas.getWidth() + ""); Log.e("TEST", "view width: " + this.getWidth() + ""); Log.e("TEST", "canvas height: " + canvas.getHeight() + ""); Log.e(

Drawing “holes” in a canvas

大憨熊 提交于 2019-12-09 09:30:42
问题 I'm trying to draw a shape like this in the onDraw method of a custom view. Unfortunately, I cannot "cut" the transparent circle on the canvas, (by drawing a circle with a Color.Transparent). Should I first draw the shape in another bitmap then draw it on the canvas provided by onDraw ? Or is it a better (simpler) way to do this ? Here is the code I tried (works with Color.WHITE) : mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.TRANSPARENT); mPaint.setStrokeWidth(4); mPaint

Drawing LinearLayout with rounded corners

瘦欲@ 提交于 2019-12-09 08:41:12
问题 I'm trying to implement a LinearLayout subclass that draws itself with rounded corners. From my research, I set setWillNotDraw(false) and overridden onDraw() to draw a rounded rectangle in the canvas: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), drawPaint, Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);