android-canvas

How to set ontouch listener for something drawn using canvas: Android

二次信任 提交于 2019-11-30 07:18:20
I have a custom view in which i am drawing one big circle and a small circle on the edge of this big circle. I would like to move the small circle and so would like to have a ontouch listener only for the small circle. Could some please tell me how to set the ontouch listener for only the small circle. public class ThermoView extends View{ private ImageView mThermostatBgrd; private ImageView mCurTempArrow; private ImageView mSetPointIndicator; public static final int THEMROSTAT_BACKGROUND = 0; public static final int THEMROSTAT_CURR_TEMP = 1; public static final int THEMROSTAT_SET_POINT = 2;

Loading large images without OutOfMemoryError

血红的双手。 提交于 2019-11-30 07:07:04
问题 I have a 5000 x 4000 px image which I want to draw onto a canvas. First I tried to load it from resources. I put it in /res/drawable . I used the following method: InputStream input = getResources().openRawResource(R.drawable.huge_image); Drawable d = Drawable.createFromStream(input, "image"); d.setBounds(...); d.draw(canvas); It worked like a charm. In this case the InputStream is an AssetManager.AssetInputStream . So now I want to load it from the sdcard. Here's what I tried to do: File f =

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

十年热恋 提交于 2019-11-30 06:29:32
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? 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 whatever you want. The draw(Canvas c) is used to manually render this view (and all of its children) to the given

2D Array grid on drawing canvas

和自甴很熟 提交于 2019-11-30 05:29:24
I am writing an pixel art app that paints images the user draws on the screen to pixel look. There are two ways to approach it. Either pixelate the image after saving or have a grid before hand so the user draws the pixel image. I don't find anything on the later method. So my issue with the first is drawing a grid where if a cell is touched I would change the color of it. I tried drawing rectangles on a canvas but that was pointless because i couldn't control the cells. I was thinking about nested for loops that creates a bitmap at each cell? The following is just a simple, illustrative

Strange crash drawing on canvas on Android 4.0.3. A/libc: Fatal signal 11 (SIGSEGV)

ぐ巨炮叔叔 提交于 2019-11-30 05:27:23
问题 I'm using a low cost tablet with Android 4.0.3. Here the log: 06-11 23:36:04.653: D/SynopticElement(1583): Size changed to 200x200 06-11 23:36:04.693: D/dalvikvm(1583): GC_FOR_ALLOC freed 62K, 12% free 7275K/8199K, paused 33ms 06-11 23:36:04.713: D/SynopticElement(1583): Size changed to 190x190 06-11 23:36:04.733: D/dalvikvm(1583): GC_FOR_ALLOC freed 9K, 12% free 7583K/8583K, paused 22ms 06-11 23:36:04.743: A/libc(1583): Fatal signal 11 (SIGSEGV) at 0xc52c9d4c (code=1) Debugging my code:

Android SDK - camera2 - Draw rectangle over TextureView

别等时光非礼了梦想. 提交于 2019-11-30 05:02:12
Im new to android development, and I'm finding it hard to find good examples on the camera2 api. Im working my way slowly through most issues, but on this one I am stuck. In the default camera, when you touch the screen to focus, it shows a rectangle of the focus area for a moment. I want to do something similar (Or in this case, the exact same thing to start off with so i can figure it out). I read somewhere (I think the TextureView page in the SDK docs) that you cant draw on a textureview while its being used as a camera preview - and calling the lock method will return null rather than a

Magnifying part of the canvas when touched

ε祈祈猫儿з 提交于 2019-11-30 04:34:28
I have a custom view that extends SurfaceView. I am drawing an image on the canvas. When the user touches a point on the canvas, i want to show a magnified view of the area around the touched co-ordinates. And preferably, as the finger moves around, i would like to update the magnified view's content accordingly. I was wondering if the android platform supports such a functionality natively. If not, can one of you point me to a good example that can get me started or share ideas on how to implement it. I don't do much 2D or 3D graphics of this sort and am still trying to understand the Canvas

Can I draw with antialiasing on canvas?

微笑、不失礼 提交于 2019-11-30 04:11:14
Can I draw with anti-aliasing on canvas? I need my circles and line have smooth edges. Drawing operations want Paint . In this Paint you set Paint.setFlags(Paint.ANTI_ALIAS_FLAG) Check this out. It fairly uses smooth edges.. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html The paint properties needed to get anti-aliasing is : mPaint = new Paint(); mPaint.setAntiAlias(true); For drawing use: mPath = new Path(); mPath.reset(); mPath.moveTo(x, y);//can be used where to trigger the path onDraw method should contain: canvas.drawPath

ZoomView canvas matrix Android

牧云@^-^@ 提交于 2019-11-30 04:07:23
I'm implementing a zoomable View from examples I've found on Stack and other websites. I do want to add a drawing feature to the view. I'm able to get the paths to show up but the scaling is way off from the image behind it. I used an example android image where I traced along the shape and the paths appeared to the left and above it. Also, zooming causes it to shift (pictures below). I've been playing around with the onDraw method where the canvas is drawn but with little success. I basically use a switch whether the onTouch responds to shifting/zooming or drawing the paths. protected void

Android - Canvas drawLine inside ImageView

孤者浪人 提交于 2019-11-30 03:37:28
问题 I've one ImageView in which I want to draw a Line. I've done the follow: mImagenCampo = (ImageView) findViewById(R.id.imagen_campo); crearPunto(mArea9M, mPaloIzq,v.getWidth(), mPaloIzq,Color.WHITE); And the function is: private void crearPunto(float x, float y, float xend, float yend, int color) { BitmapDrawable bmpDraw = (BitmapDrawable) mImagenCampo.getDrawable(); Bitmap bmp = bmpDraw.getBitmap().copy(Config.RGB_565, true); Canvas c = new Canvas(bmp); Paint p = new Paint(); p.setColor(color