android-canvas

How to make view resizable on touch event

一世执手 提交于 2019-12-18 01:26:29
问题 See the following image I want to change the shape of highlighted view by dragging its corner.. not necessory the view after dragging the corner should be rectangle it can be any arbitary shape how to achive this?? now i have done the 4 corners movable on touch event but the shape is not changing package com.assignment.DragDrop; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import

How to get total area covered while drawing path on canvas android?

巧了我就是萌 提交于 2019-12-18 00:17:18
问题 Im using below code to draw line on bitmap canvas while finger touch move... here i posted partial code and it is working fine.. As shown in below image, the black and white bitmap erased on touch drag.. I made canvas transparent so the parent layout background(color image) is getting visible. I want to know , how much area is erased(like 50% or 60% of bitmap ).. is there any way to find that? //Erasing paint mDrawPaint = new Paint(); mDrawPaint.setAntiAlias(true); mDrawPaint.setDither(true);

Draw smoothly scaled bitmaps on Canvas

霸气de小男生 提交于 2019-12-17 21:48:30
问题 This is how I draw Bitmap on Canvas in my Android app: canvas.save(); canvas.scale(scale, scale, x, y); canvas.drawBitmap(bitmap, x, y, null); canvas.restore(); However the Bitmap is not scaled smoothly, no anti-aliasing is performed. How can I enable anti-aliasing? 回答1: Try this: Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawBitmap(bitmap, x, y, paint); 回答2: Both Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); or paint

How to draw filled triangle on android Canvas

有些话、适合烂在心里 提交于 2019-12-17 18:50:34
问题 I have class MyView that extends View class. MyView should draw filled triangle. I drew a triangle but I cannot get it filled. This is my onDraw() method: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(android.graphics.Color.BLACK); canvas.drawPaint(paint); paint.setStrokeWidth(4); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Point a = new Point(0, 0); Point

Canvas.clipPath(Path) not clipping as expected

狂风中的少年 提交于 2019-12-17 18:34:40
问题 I'm trying to clip a canvas drawing operation to an arc-shaped wedge. However, I'm not getting the intended result after setting the clipping path to the canvas. For illustration, here is what I'm doing: path.reset(); //Move to point #1 path.moveTo(rect.centerX(), rect.centerY()); //Per the documentation, this will draw a connecting line from the current //position to the starting position of the arc (at 0 degrees), add the arc //and my current position now lies at #2. path.arcTo(rect, 0, -30

Android transparent canvas (surfaceview)

时光毁灭记忆、已成空白 提交于 2019-12-17 17:58:18
问题 I've got a panel which is placed on top of another view via a relativelayout. I would like to give this panel a transparent background, but didn't find the correct way to do this after searching for some hours. When I set the alpha back to 0 I end up with a black background. Hopefully someone here can help me with this. Thanks a lot! The panel is drawn via this code: import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet

How to Clip a Star in android ? But the appearance of the star is clear

╄→гoц情女王★ 提交于 2019-12-17 16:33:16
问题 First to see the below images. package com.syncfusion.rating; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Region; import android.view.View; /** * Created by chozarajan.pandiyarajan on 10/9/2015. */ public class SfRatingItem extends View { private int fillColor,minDim,topXPoint,topYPoint; private double bigHypot,bigA,bigB,littleHypot,littleA,littleB,value;

Android: Enable Scrollbars on Canvas-Based View

ⅰ亾dé卋堺 提交于 2019-12-17 16:24:03
问题 I have a custom view that extends View. It displays drawn shapes, and allows the user to add to those drawings via drawing touch events to the View via onDraw. I've enabled the ScaleGestureDetector so that the user can zoom in on a particular section and draw, but as I am using single-touch to draw, they cannot use their finger to pan around the zoomed in View. I've tried to enable scrollbars for the View such that when they are zoomed in, the scrollbars are displayed and can be used by the

Adding a colored background with text/icon under swiped row when using Android's RecyclerView

你离开我真会死。 提交于 2019-12-17 15:26:58
问题 EDIT: The real problem was that my LinearLayout was wrapped in another layout, which caused the incorrect behavior. The accepted answer by Sanvywell has a better, more complete example of how to draw a color under swiped view than the code snippet I provided in the question. Now that RecyclerView widget has native support for row swiping with the help of ItemTouchHelper class, I'm attempting to use it in an app where rows will behave similarly to Google's Inbox app. That is, swiping to the

Drawable image on a canvas

喜夏-厌秋 提交于 2019-12-17 06:28:43
问题 How can I get an image to the canvas in order to draw on that image? 回答1: 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. 回答2: You need to load your image as