• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Understanding Canvas and Bitmap

Moynzy

Lurker
Dec 9, 2015
4
0
Hello!

I am new to Android Studio/ development.

I have worked with XCode + Swift, and I have managed to implement a simple scribble application.

However, I'm finding it difficult to do it in Android.

I have checked the documentation and YouTube for answers regarding to the graphics API.

The application captures touch input from the user and must display it on to the screen.

Now can you paint directly to the canvas, or must you create a bitmap containing what the user drew, then display it on to the bitmap?
If so, doesn't the canvas takes priority in the layer, i.e if you have a button and your canvas is full screen then the button will not appear.

How does the drawing functionality work (sorry, i'm lost for words and can't quite clearly explain)/
 
You can draw directly on to a Canvas. The Canvas API contains methods such as drawRect(), drawLine() etc to allow you to do this.

You can create a class which extends View. Then override certain methods, primarily onDraw(), which takes as a parameter, a Canvas object. You can then directly render your content on the Canvas.
 
Upvote 0
You can draw directly on to a Canvas. The Canvas API contains methods such as drawRect(), drawLine() etc to allow you to do this.

You can create a class which extends View. Then override certain methods, primarily onDraw(), which takes as a parameter, a Canvas object. You can then directly render your content on the Canvas.

Hi, cheers for the explanation.

I have extended my custom class to extend View. onDraw has been implemented, however, if i set the content view to my custom view class, then I am unable to view the buttons.

If I am to have a button that increases a brushes opacity/ size ect. Then it would be impossible, since the content view isn't r.layout.view (I believe that's the code).
 
Upvote 0
Sorry, I've not actually used graphics before in an app, so just suggesting some things. I believe there's a 'layering' capability that could be what you need to look at. Sounds like the canvas is obscuring everything else.
But do have a look through the sample apps in Android Studio, as something there may be able to help you.
 
Upvote 0
From my understanding, most applications do not really need to use the core graphics API right, since images are made in a different application like photoshop, and then imported into the application.

Yeah, my thoughts are the same, the view on the GUI builder is not appearing due to the custom view being at the top.

I'll look through the sample applications, many thanks for your time though.
 
Upvote 0
Well you can render bitmaps, but it sounds like you are taking input from the user, and wanting to draw vector graphics on the screen directly? This would mean that performance is critical, and introducing a bitmap might cause delays.
Just thinking out loud here, I might be talking a load of rubbish.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones