android-canvas

How to get canvas pixel

牧云@^-^@ 提交于 2019-11-30 14:57:27
I have a canvas on which I draw lines: //see code upd I need to make the pipette tool which will take color from my canvas. How may I make it? Code upd: private static class DrawView extends View { ... public DrawView(Context context) { super(context); setFocusable(true); mBitmap = Bitmap.createBitmap(640, 860, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); this.setDrawingCacheEnabled(true); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

How to Get a soundcloud like waveforms in Android

送分小仙女□ 提交于 2019-11-30 13:58:16
I have generated a simple waveform like the picture below with my code. But I want to give more gap between each line I want it to be like the soundcloud waves like the picutre below. Here is my code: public class VisualizerView extends View { private static final int LINE_WIDTH = 15; // width of visualizer lines private static final int LINE_SCALE = 55; // scales visualizer lines private List<Float> amplitudes; // amplitudes for line lengths private int width; // width of this View private int height; // height of this View private Paint linePaint; // specifies line drawing characteristics //

View onDraw(Canvas c) versus draw(Canvas c) in android?

前提是你 提交于 2019-11-30 13:14:27
问题 I am new to android development, I am exploring about View . I come across to known two methods onDraw(Canvas c) and draw(Canvas c) . Could please explain me the difference and usage of these two methods? Which method will give better performance(FPS) when updating canvas with images? 回答1: There is difference between them The onDraw(Canvas c) is a override method and automatically called when the view is being rendered. Here you can do your additional drawing like make circles, lines or

Android UnsupportedOperationException at Canvas.clipPath

蹲街弑〆低调 提交于 2019-11-30 13:00:43
I am using the image crop library from here https://github.com/lvillani/android-cropimage in my project to crop images stored on device. However, certain users are reporting crashes with the following stack trace java.lang.UnsupportedOperationException at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:413) at com.android.camera.HighlightView.draw(HighlightView.java:101) at com.android.camera.CropImageView.onDraw(CropImage.java:783) at android.view.View.draw(View.java:11006) at android.view.View.getDisplayList(View.java:10445) at android.view.ViewGroup.drawChild(ViewGroup.java:2850) at

Implementing an eraser in an Android drawing app - black trail and then transparent

一曲冷凌霜 提交于 2019-11-30 12:04:37
问题 I have an drawing app for Android and I am currently trying to add a real eraser to it. Before, I had just used white paint for an eraser, but that won't do anymore since now I allow background colors and images. I do this by having an image view underneath my transparent canvas. The problem that I am facing is that whenever I enable my eraser, it draws a solid black trail while I have my finger down, but once I release it goes to transparent. See the screen shots below: This is how it looks

How to draw a bitmap to another, but into a given quadrilateral (not necessary a rectangle)?

本小妞迷上赌 提交于 2019-11-30 09:52:29
问题 Suppose I have 2 bitmaps. One is smallBitmap, and one is largeBitmap. I want to draw the entire smallBitmap into largeBitmap, but only to a part of largeBitmap, and not in a straight regtangle, but into a quadrilateral instead. I think a sketch will best describe what I mean: An example of this scenario is a tilted smartphone image (like this or this), that you need to put a screenshot into its screen. The input is: smallBitmap, largeBitmap, "quadrilateral" coordinates of the largeBitmap

Does a line contain a point

流过昼夜 提交于 2019-11-30 09:44:41
问题 I want the user to be able to drag the edges of a square around the canvas. With my current solution it works but has glitches, sometimes an edge cannot be selected. Is there a clean way to tell if a line has been clicked (e.g. passes through a coordinate)? This is how I'm currently testing: // check edge pressed, edge is the line between to // coords e.g. (i) & (i = 1) for (int i = 0; i < coords.size(); i++) { p1 = coords.get(i); if ((i + 1) > (coords.size() - 1)) p2 = coords.get(0); else p2

How to get current canvas?

不问归期 提交于 2019-11-30 08:45:59
I have DrawView. If I touch this view it draws small circles. I wont to draw circles but not to touch view - with help function "setPoints". What I do: package com.samples; import ... public class DrawView extends View { ArrayList<Point> points = new ArrayList<Point>(); Paint paint = new Paint(); private int pSize = 5; private int pColor = Color.BLACK; public DrawView(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v

Android Implement onTouchListener on path objects

蓝咒 提交于 2019-11-30 07:50:58
问题 I have created a path objects as shown below which draws a different shapes.Different buttons response to drawing different shapes on the canvas. I would like to shift the path objects that i have created in the canvas but I do not know how to. I only know the method of implementing ontouchlistener on a bitmap and not on path objects. my codes are as follows: ArrayList<Path> paths = new ArrayList<Path>(); @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub

Draw a circle on an existing image

泄露秘密 提交于 2019-11-30 07:23:05
I'm trying to draw a circle on an image which placed as res/drawable/schoolboard.png . the image fills the activity background. the following does not work: Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.schoolboard); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLUE); Canvas canvas = new Canvas(bitmap); canvas.drawCircle(60, 50, 25, paint); ImageView imageView = (ImageView)findViewById(R.drawable.schoolboard); imageView.setAdjustViewBounds(true); imageView.setImageBitmap(bitmap); any help will be highly appreciated. thanks. moh.sukhni