android-canvas

How to display Text in Android Canvas ShapeDrawable with in the RectShape or OvalShape?

安稳与你 提交于 2019-11-26 14:47:44
问题 I'm trying to display Text in RectShape which uses ShapeDrawable to display in Canvas. I'm able to display RectShape in this code, but looking for how to display the String on that! public class CustomDrawableView extends View { private ShapeDrawable mDrawable; public CustomDrawableView(Context context) { super(context); int x = 10; int y = 10; int width = 300; int height = 50; mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.getPaint().setColor(0xff74AC23); mDrawable.setBounds(x, y,

Android : Draw Circle With Text Inside

試著忘記壹切 提交于 2019-11-26 14:12:19
问题 I need to draw three circles in my fragment ,the circles differ in size, I refer this link The result i obtained is this This is my XML Code : UPDATED <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <TextView android:id="@+id/large_volume" android:layout_width="185dp" android:layout_height="185dp" android:background="@drawable

Drawing an outer shadow when drawing an image

懵懂的女人 提交于 2019-11-26 14:05:42
问题 I currently create a rounded version of an image in my app by drawing to a canvas. I would like to draw a faint outershadow around the image, but I cant quite get it right. I have 2 questions: 1. How can I draw an outer shadow (I can only seem to draw a shadow with a x or y offset) 2. How can I draw the shadow so that it does not have the artifacts shown in the attached image. Code: ![public Bitmap getRoundedCornerBitmap(Bitmap bitmap, float cornerRadius) { Bitmap output = Bitmap.createBitmap

Android View.onDraw() always has a clean Canvas

六月ゝ 毕业季﹏ 提交于 2019-11-26 13:18:49
问题 I am trying to draw an animation. To do so I have extended View and overridden the onDraw() method. What I would expect is that each time onDraw() is called the canvas would be in the state that I left it in and I could choose to clear it or just draw over parts of it (This is how it worked when I used a SurfaceView) but each time the canvas comes back already cleared. Is there a way that I can not have it cleared? Or maybe save the previous state into a Bitmap so I can just draw that Bitmap

Android BlurMaskFilter has no effect in canvas.drawOval while text is blurred

倖福魔咒の 提交于 2019-11-26 13:04:31
问题 I\'ve been trying to create a custom view which has blurred shapes under text. The problem is that the BlurMaskFilter has no effect on any shape that I draw on the canvas. Here is how I\'m initialising the Paint objects in the constructor: paint = new Paint(0); paint.setColor(0xffffffff); paint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL)); mShadowPaint = new Paint(0); mShadowPaint.setColor(0xff333333); mShadowPaint.setMaskFilter(new BlurMaskFilter(10, BlurMaskFilter.Blur

Crop square image to circle - Programmatically

浪子不回头ぞ 提交于 2019-11-26 12:09:22
问题 i was searching for past one day and i was not successful . i get the image from API , and i download it to a bitmap file using the following code . private Bitmap DownloadImage(String URL) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(URL); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (IOException e1) { e1.printStackTrace(); } return bitmap; } private InputStream OpenHttpConnection(String urlString) throws IOException { InputStream in = null;

Android Center text on canvas

风格不统一 提交于 2019-11-26 11:45:50
问题 I\'m trying to display a text using the code below. The problem is that the text is not centered horizontally. When I set the coordinates for drawText , it sets the bottom of the text at this position. I would like the text to be drawn so that the text is centered also horizontally. This is a picture to display my problem further: @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //canvas.drawRGB(2, 2, 200); Paint textPaint = new Paint()

Draw multi-line text to Canvas

有些话、适合烂在心里 提交于 2019-11-26 11:40:52
A hopefully quick question, but I can't seem to find any examples... I'd like to write multi-line text to a custom View via a Canvas , and in onDraw() I have: ... String text = "This is\nmulti-line\ntext"; canvas.drawText(text, 100, 100, mTextPaint); ... I was hoping this would result in line breaks, but instead I am seeing cryptic characters where the \n would be. Any pointers appreciated. Paul Unfortunately Android doesn't know what \n is. What you have to do is strip the \n and then offset the Y to get your text on the next line. So something like this: canvas.drawText("This is", 100, 100,

Out of Memory error with Bitmap

坚强是说给别人听的谎言 提交于 2019-11-26 11:24:02
During runtime, I am trying to put an image in the surface view. When I tried using the image from the Drawable folder I got Out of memory error. After a quick search in the stackoverflow, I found that there will be some relief if we access the image from the asset folder. But still I get the Out of memory error during runtime. I have analyzed and found that scaling will help in resolving this kind of memory related issues. The thing is that I have the image size of 1280 x 720 and the device size also the same. Hence I feel like the scaling will not have any effect. As we have experts in this

Getting the pixel color value of a point on an Android View that includes a Bitmap-backed Canvas

一世执手 提交于 2019-11-26 11:23:27
问题 I\'m trying to figure out the best way to get the pixel color value at a given point on a View. There are three ways that I write to the View: I set a background image with View.setBackgroundDrawable(...). I write text, draw lines, etc., with Canvas.drawText(...), Canvas.drawLine(...), etc., to a Bitmap-backed Canvas. I draw child objects (sprites) by having them write to the Canvas passed to the View\'s onDraw(Canvas canvas) method. Here is the onDraw() method from my class that extends View