android-canvas

Is it possible to display multi-color text with one call to Canvas.drawText()?

感情迁移 提交于 2019-11-28 23:55:17
I would like to use Canvas.drawText() to display multi-color text. More specifically, I want to highlight a substring of the text passed to the drawText() method. The text is in the form of a SpannableString with 0 or more ForegroundColorSpan objects. Looking at the Canvas code, it appears that a .toString() call on the passed CharSequence, means that this is not possible. Is there an alternative way? EDIT: The text may occasionally change (total changes, not incremental). Also, there are potentially multiple texts positioned in different unrelated locations in the custom view. Renard Yes it

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

安稳与你 提交于 2019-11-28 21:28: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); mDrawPaint.setStyle(Paint.Style.STROKE); mDrawPaint.setStrokeJoin(Paint.Join.ROUND); mDrawPaint

Understanding how actually drawRect or drawing coordinates work in Android

泪湿孤枕 提交于 2019-11-28 19:52:28
问题 I am trying to draw a rectangle over a canvas and I am facing troubles to understand the in-depth of rectangle draw of Android. I've read tutorials and every possible but I am stuck. Here in the image , the red rectangle is my target. Irrespective of any rectangle size I need to draw the red rectangle bit above the base and in the middle of the rectangle. The worst nightmare I am facing here is understanding the X,Y Width and Height coordinates. Can anyone explain how that math works,

Android Live Wallpapers — OpenGL vs Canvas

自作多情 提交于 2019-11-28 19:35:23
I am a fairly "newb" Android developer, and I would like one of my first projects to be a live wallpaper, however I am conflicted on whether I should be focusing on Canvas or OpenGL for it. Being new to this I know I should master Canvas first since it is easier to use, but I prefer to learn from real world projects that I have an interest in, even if it's a little backwards at times. I have used both before in very basic ways, and I understand the general concepts to them, but I am not sure how they transfer over to the realm of live wallpapers. I figure that the full blown speed of OpenGL

how to make full circular image view in android [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-28 19:09:35
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to make an image fit into a circular frame in android I want a 360 degree circular shape Image View, I found related solutions on stackoverflow, but they were all yielding rounded corners in image view. But i want full circular image view. For rounded corners image view links are: Rounded corners in imageView How to make an ImageView with rounded corners? Any thoughts. 回答1: Get the Bitmap: Bitmap bitmap =

Android - How to circular zoom/magnify part of image?

和自甴很熟 提交于 2019-11-28 17:34:50
I am trying to allow the user to touch the image and then basically a cirular magnifier will show that will allow the user to better select a certain area on the image. When the user releases the touch the magnified portion will dissapear. This is used on several photo editing apps and I am trying to implement my own version of it. The code I have below does magnify a circular portion of the imageview but does not delete or clear the zoom once I release my finger. I currently set a bitmap to a canvas using canvas = new Canvas(bitMap); and then set the imageview using takenPhoto.setImageBitmap

Draw smoothly scaled bitmaps on Canvas

五迷三道 提交于 2019-11-28 16:32:36
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? Try this: Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); paint.setDither(true); canvas.drawBitmap(bitmap, x, y, paint); Sileria Both Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); or paint.setFilterBitmap(true); worked for me but be very careful, on my game it cut down the FPS from 30FPS to

Measuring text width to be drawn on Canvas ( Android )

孤街浪徒 提交于 2019-11-28 16:26:38
Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it? Have you looked at android.graphics.Paint.measureText(String txt) ? hamid reza zavareh Paint paint = new Paint(); Rect bounds = new Rect(); int text_height = 0; int text_width = 0; paint.setTypeface(Typeface.DEFAULT);// your preference here paint.setTextSize(25);// have this the same as your text size String text = "Some random text"; paint.getTextBounds(text, 0, text.length(), bounds); text_height = bounds.height(); text_width =

How to make any view to draw to canvas?

孤街醉人 提交于 2019-11-28 15:21:32
问题 I have a short question: Suppose I have a (mutable) bitmap that I need to modify (add images, texts, etc...) . Instead of messing around with many special classes for drawing to the canvas (paint, canvas, matrices and so on), I was thinking why not use the built in classes of Android for this task and only if i need really customized operations i could still use the canvas ? So, for example, in order to show any kind of view (that has no parent, of course) on the bitmap, I could call the next

How do the pieces of Android's (2D) Canvas drawing pipeline fit together?

独自空忆成欢 提交于 2019-11-28 14:42:26
问题 I would like to have a better understanding of how the components of Android's (2D) Canvas drawing pipeline fit together. For example, how do XferMode, Shader, MaskFilter and ColorFilter interact? The reference docs for these classes are pretty sparse and the docs for Canvas and Paint don't really add any useful explanation. It's also not entirely clear to me how drawing operations that have intrinsic colors (eg: drawBitmap , versus the "vector" primitives like drawRect ) fit into all of this