android-canvas

Canvas Zoom goes to point (0,0)

落花浮王杯 提交于 2019-12-06 03:25:10
问题 I am having a problem in zooming the canvas. I have made a customized view in which I am drawing relationship diagrams now when I zoom out the canvas in goes to the position (0,0). I have seen different threads and questions but could not find appropriate answer. What i am doing in onDraw Method is. canvas.scale(mScaleFactor, mScaleFactor); I have also seen the canvas.scale(x, y, px, py) method but i do not know how to get the pivot points of x and y. public boolean onScale

Show marker inside a resource drawable which obtained from url

佐手、 提交于 2019-12-06 01:07:48
问题 Here is the map page I have, which shows all the users of my App. Also the images(markers) are obtained from the URL given from my server. These markers has to put inside a Drawable(a circle like image as shown). I created a circle like Bitmap from the url using Canvas. public Drawable showMe(String url) { Bitmap bitmap=null; try { URL newurl = new URL(url); bitmap = BitmapFactory.decodeStream(newurl.openConnection().getInputStream()); } catch (MalformedURLException e) { // TODO Auto

Android triangle custom buttons

↘锁芯ラ 提交于 2019-12-05 22:34:55
I want to make 2 diagonal triangle buttons like in this question . How can I achieve this? Should I make a drawable xml with a rectangle and rotate it somehow? Should I make an image and make it clickable only on the triangle parts with the help of mathematics? package com.example.buttonsView; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Path.FillType; import android.graphics.Point; import android.graphics.RectF; import android.graphics.Region; import android

How to use onDraw(Canvas) to obtain a bitmap snapshot of the WebView(Android)

ⅰ亾dé卋堺 提交于 2019-12-05 22:03:33
I used to use capturePicture() method to make a snapshot of my WebView. This method was deprecated in API level 19. The doc say that "Use onDraw(Canvas) to obtain a bitmap snapshot of the WebView", but I really don't know how it means. Will you please teach me how to solve the problem? Richard Guan The following should work: float scale = webView.getScale(); int webViewHeight = (int)(webView.getContentHeight() * scale); Bitmap image = Bitmap.createBitmap(webView.getWidth(), webViewHeight, Config.ARGB_8888); Canvas canvas = new Canvas(image); webView.draw(canvas); 来源: https://stackoverflow.com

emojis not rotating with canvas

本小妞迷上赌 提交于 2019-12-05 18:42:27
I have created an applications that allows users to paint with text, including emojis. The user can rotate and resize the text to their liking. The problem occurs when the user rotates text that includes emojis. As you can see, there is unwanted overlap. I have deduced that this is because i draw the text twice to achieve a border affect. Whats interesting, is that the problem solves itself if the text size exceeds a certain amount. this can be seen in the bottom most test. Here is the code that drew the above image: public void draw(Canvas c, int x, int y) { Rect re = new Rect(); Paint p =

Multiple RelativeSizeSpan on same line

醉酒当歌 提交于 2019-12-05 18:36:19
I'm trying to use two RelativeSizeSpan next to each other, but a big gap appears in between. See what I want to achieve and what I'm getting. This is how I'm building the Spanned instance String formattedValue = "25%"; SpannableStringBuilder ssb = new SpannableStringBuilder(formattedValue); ssb.append("\n"); ssb.append(otherValue); int firstSpanEnd = formattedValue.length(); ssb.setSpan(new RelativeSizeSpan(1.5f), 0, firstSpanEnd-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new RelativeSizeSpan(0.3f), firstSpanEnd, firstSpanEnd+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); And this is how I'm

How to move multiple bitmaps in single canvas android

五迷三道 提交于 2019-12-05 17:54:46
I want to move multiple bitmap on the same canvas. Using below code i can move one bitmap when touch on the screen but, i can't identify the touch event on the bitmap so that i couldn't move specific bitmap. public class DrawTopologyView extends View { Paint paint = new Paint(); Bitmap zed_bitMap, lamp_on_bitmap, fan_on_bitmap, ac_on_bitmap; int START_X = 5; int START_Y = 5; float x = 500-24,y=START_Y; public DrawTopologyView(Context context) { super(context); zed_bitMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.zed); lamp_on_bitmap = BitmapFactory.decodeResource

getDrawingCache is not updated

99封情书 提交于 2019-12-05 17:50:54
I'm calling getDrawingCache in the onDraw function. The problem is that it contains the changes to the canvas only in the first time, and after that, it's not updated at all with the new changes. Here's my code: paintAction.draw(canvas); if (paintAction.isPermanentChange()) { Bitmap partialBitmap=getDrawingCache(); int numColored=0; for (int index1=0;index1<partialBitmap.getWidth();index1++) { for (int index2=0;index2<partialBitmap.getHeight();index2++) { if (partialBitmap.getPixel(index1,index2)==0xFF000000) numColored++; } } Log.i("PaintDroid","Bitmap pixels: " + numColored); int areaWidth

draw an image in the center of another rectangle using canvas

若如初见. 提交于 2019-12-05 16:07:13
In my view I have a big rectangle, the rectangle can move. When the rectangle moves to someplace, I want to draw image in the center of the big rectangle. My question is that I cannot put the center of the image to the center of the rectangle. I used: canvas.drawBitmap(rotatedBitmap, matrix, paint) canvas.drawBitmap(rotatedBitmap, left, top, paint) but i cannot find canvas.drawBitmap(rotatedBitmap, centerX, centerY, paint), so I want to use matrix, but the matrix also moves image from the left and top start, not from center, can you give some clue to draw the pic in the center of the rectangle

Android. Canvas scale and translate

本小妞迷上赌 提交于 2019-12-05 16:02:43
I created custom view where you can touch and scale it. Most of work was created with the help of this post Next i observe that if i want to zoom in image it is always zooming to top left corner. Here is my onDraw() method: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); canvas.translate(mPosX, mPosY); canvas.scale(mScaleFactor, mScaleFactor); // actual drawing canvas.getClipBounds(mRect); canvas.restore(); } So this is normal behaviour for canvas.scale(px, py); I want from my view be scaling to center point(later i will take focalX , focalY coordinates,