android-canvas

Taking Screenshot

余生颓废 提交于 2019-11-26 20:28:35
问题 I'm developing an application for taking screenshots in the device. In this application, we can draw anything on the screen. For this I am using Canvas, Paint and Path to do this. I'm using this code to take screenshots: public void saveScreenshot() { if (ensureSDCardAccess()) { Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); onDraw(canvas); File file = new File(mScreenshotPath + "/" + System.currentTimeMillis() + "

Rotating Image on A canvas in android

旧街凉风 提交于 2019-11-26 19:46:51
I want to Rotate Image according to a specific angle in android ,some thing like a compass... I have this code...it works on drawPath() but i want to replace the path and the Drawing thing with image.. I tried to create a bitmap image ,DrawBitmapImage , but the image does not Rotate like the path..Any Help PLease? public void draw(Canvas canvas) { double angle = calculateAngle(currentLongitude, currentLatitude, targetLongitude, targetLatitude); //Correction; angle-=90; //Correction for azimuth angle-=azimuth; if((getContext() instanceof Activity) && ((Activity)getContext()).getWindowManager()

How to set gradient style to paint object?

荒凉一梦 提交于 2019-11-26 19:23:05
问题 The code for drawing an arrow with Style: Fill is given below: paint.setColor(Color.parseColor("#bdc0dc")); paint.setStyle(Style.FILL); canvas.drawPath(arrowPath, paint); paint.setColor(Color.BLACK); paint.setStyle(Style.STROKE); paint.setStrokeWidth(2); canvas.drawPath(arrowPath, paint); And the output I obtain is this : Now what I want do is set style to Gradient(Style.gradient not present in android...) to obtain the arrow similar to the image given below : How do i do it ? I tried adding

Drawing on Canvas and save image

ぃ、小莉子 提交于 2019-11-26 19:06:29
问题 I am new to the Android Graphics class. I want to draw an image(actually a signature kind) using the touch events and want it to be saved on SDcard when I want to save it. I have scanned through the web for any such tutorials but I have not found any. Can anyone please tell me how to draw on canvas using the touch events and save it. Any tutorials or sample code will be of great help. 回答1: I saw really good code on android developers, but I can't find it anymore... It's output is bezier

Work around Canvas.clipPath() that is not supported in android any more

拈花ヽ惹草 提交于 2019-11-26 18:55:44
From android 3.0 the clipPath() method is no longer supported in devices with hardware acceleration turned on.(Read this article for more details). I am working with canvas and I need to draw rounded image. Any ideas about how can I do that? *I can't turn the hardware acceleration off, I am looking for other solution. Answered: Tnx @Malcolm for your answer. I found a good example that demonstrate this technique , it's basically a mask. Canvas.clipPath() support with hardware acceleration has been reintroduced since API 18 . The best way to work around the problem is calling setLayerType(View

How to add rectangles on top of existing rectangle in canvas

社会主义新天地 提交于 2019-11-26 18:34:45
问题 I'm trying to add some red rectangles within my existing canvas on top of specific boxes exactly like the expected result image but they don't appear at all as my code shows the current undesired outcome when I deploy my app. My code is to create 4 rectangles on the top row and 4 rectangles on the bottom row but I only want this to be added on top of boxes 2-6 but I know extra code needs to be added for the red rectangles on top of boxes 1 & 7. Does anyone know what I'm doing wrong and how to

Android: Drawing a canvas to an ImageView

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:12:59
问题 I'm new to android programming and what I'm trying to figure out is this; In my layout i have a TextView, ImageView, and Button, all on a vertically oriented LinearLayout. I want to be able to dynamically draw circles in the ImageView, without disturbing the rest of my layout(textview/button). I'm trying to create a canvas, and use the drawcircle function within canvas to set the location of the circle. And then draw that canvas to my imageview in some way. I cannot get this to work, is there

MediaRecorder and VideoSource.SURFACE, stop failed: -1007 (a serious Android bug)

佐手、 提交于 2019-11-26 18:01:23
I'm trying to record MediaRecorder without using Camera instance but using Surface video source (yes it's possible, but it turned out that it's not that perfect) - mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); I just write what the issue: Next code works only on some devices and works temporary on some devices after a recent device rebooting or doesn't work at all If it doesn't work ok MediaRecorder.stop() method fails with the next error E/MediaRecorder: stop failed: -1007 W/System.err: java.lang.RuntimeException: stop failed. at android.media.MediaRecorder.stop(Native

Bezier curve and canvas

我的未来我决定 提交于 2019-11-26 17:39:10
问题 How I can draw bezier curve in canvas. I have only start point and end point. I want to draw line from start point to end point. How I can do this? 回答1: You can use Path.quadTo() or Path.cubicTo() for that. Examples can be found in the SDK Examples (FingerPaint). In your case you would simply need to calculate the middle point and pass then your three points to quadTo() .. Some code for you: (x1,y1) and (x3,y3) are your starting and ending points respectively. create the paint object only

How to draw a filled triangle in android canvas?

痞子三分冷 提交于 2019-11-26 17:30:47
So I'm drawing this triangle in android maps using the code below in my draw method: paint.setARGB(255, 153, 29, 29); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Path path = new Path(); path.moveTo(point1_returned.x, point1_returned.y); path.lineTo(point2_returned.x, point2_returned.y); path.moveTo(point2_returned.x, point2_returned.y); path.lineTo(point3_returned.x, point3_returned.y); path.moveTo(point3_returned.x, point3_returned.y); path.lineTo(point1_returned.x, point1_returned.y); path.close(); canvas.drawPath(path, paint); The pointX_returned are the