Embed canvas into an activity - android

I'm writing a app for a tablet. I have a activity that contains text and buttons and an area where I want to put something that is drawn on a canvas. When buttons are pressed I want to draw a grid that will contain lines, text and images, built dynamically.
What I can't figure out is after I draw this on the canvas how to put/embed the canvas into the activity in a certain area(ImageView?). I have a prototype app where I can draw the grid, but I can't figure out how to put the canvas into the activity.
Any help or point me to an article would be really appreciated. Thanks

First you get a bitmap from your canvas then you can use it in your ImageView via ImageView.setImageBitmap(mCanvasBitmap)

Related

Android canvas: Is it possible to add images from gallery?

In some paint apps or note taking apps, they will allow you to add text and images in addition to drawing stuff.
Now I know that I can create a custom view and override on touch events and build paths and draw them on canvas.
But what I don't know is this: In apps like mentioned above I am confused if they add images as image views or they add images directly drawn on canvas.
I mean do they create new imageview and set the gallery image to it, or they simply add the image directly to the canvas.
Any thoughts?
Thanks.
They draw it directly to the Canvas. Notice the Canvas class (which is how Views draw) has a drawBitmap and drawText functions. Generally in a drawing app the entire area you draw on will be just 1 view.

How to create an interactive image in Android?

I want to put a photo in Android app that you can touch it in some parts and can edit it with an EditText, Check Box, etc.
You should look into the Canvas class as a basis for this. You can draw bitmaps, text, and perform image manipulations on the Canvas.
CanvasView is a nice simple API that builds on Canvas allowing you to draw/erase and add text/images onto a Canvas easily.

How to select the image by drawing a line around it in android?

I am creating a simple free hand drawing app. In my layout, i have two images placed. I need to select the correct image, by drawing a free hand circle around the image. As i am new to android, i don't know the correct way to do it. I tried some ways to draw free hand drawings like, calling a drawing view class and using the onDraw method to paint the path using canvas, but for that i had to kept my setContentView() to drawing view class. But I want to use my layout with images as setContentView() and make free hand drawings to draw around the images. Can somebody help me? Thank you in advance.

Drawing on canvas help needed - Android

Hi I am new to Android Canvas. I want to know how can I draw on canvas using a bitmap.
Basically I want to be able to draw multiple figures in my canvas dynamically. After reading about canvas I figured out this much that for each figure I may have to create a new bitmap attach a canvas to it draw a figure in that bitmap and finally draw that bitmap in the canvas of onDraw() method using drawBitmap function in order to view it on screen. Hope I am right till this part ? If not please correct me. I am open for your opinions and suggestions :)
Also I would like to know if I can apply onTouch event separately to the bitmaps or canvas created dynamically or it can be only applied to canvas of onDraw cause I want the images which are being drawn in my canvas to be able to move at users will?
You are right about the first part. However in second part u cannot add onTouch listener as u have said. As far as I know listeners can only be added to Views. And also its not like you are adding onTouch Listener to the canvas of the onDraw() method u are basically applying to the whole view a view cannot have two same listeners.

Reducing the Canvas drawing area,and fetching the coordinates on the canvas as a grid(or array of coordinates)?(Android)

Is it possible to reduce my drawing area of Canvas instead of making the whole screen available for drawing? I have placed Buttons and TextViews, but apparently, I can draw over them. They don't hide, but behind them the Canvas gets colored.
And secondly, is it possible to retrieve all the coordinates of the Canvas as a grid(or array of coordinates)? Like:
With coordinates filling the regions that is drawn upon, and other boxes of the grid being empty?
kindly help! :-)

Categories

Resources