Cookies and Canvas OR Private Events) Choose your event or favorite featured artwork and REGISTER; Check the start time of your event and arrive a few minutes early to sit in your favorite seat! All of your supplies are waiting to create your masterpiece Including an apron to keep your clothes clean. Hang on to your paintbrush for a night of. Adult paint and sip kit, paint and wine, pre drawn canvas, Paint Party, Do It Yourself Kit, paint by numbers, weed art, paint with a twist ToGoghPaintKits 4.5 out of 5 stars (19).
Overview
Let's take a look at building a custom view that allows the user to paint on the screen by pressing down their finger. This will illustrate how to build custom components, how to draw shapes and paths on a view and also how to handle user touch interactions.
Creating our Custom View
Create a simple class for drawing that extends View called SimpleDrawingView
:
Add this to the XML layout for activity so our custom view is embedded within:
Simple Drawing with Canvas
Let's try drawing a couple of circles on screen. This requires us to define a Paint
object which controls the styling and color of what is drawn. Let's start by preparing the paint:
Now that we have the paint setup to have a black color and configured a particular stroke style, let's try to draw a few circles with different colors. All drawing that happens in a view should take place within the onDraw
method which is automatically called when a view is rendered:
Notice that onDraw
passes us a canvas
object which we use to draw leveraging the Paint
we defined earlier. The drawCircle
method accepts the x, y and radius of the circle in addition to the paint. This renders the following:
Handling Touch Interactions
Suppose now we wanted to draw a circle every time the user touches down on the drawing view. This would require us to keep track of an array of points for our circles and then append a point for each onTouch
event triggered:
with this, a black circle is drawn each time we press down:
Drawing with Paths
So far we have explored the onDraw
method of a view and we were able to draw circles onto the view based on touch interactions with the view. Next, let's improve our drawing application by removing the list of circles and instead drawing with paths. The Path class is ideal for allowing the user to draw on screen. A path can contain many lines, contours and even other shapes. First, let's add a Path
variable to track our drawing:
Next, let's append points to the path as the user touches the screen. When the user presses down, let's start a path and then when they drag let's connect the points together. To do this, we need modify the onTouchEvent
to append these points to our Path object:
and then let's alter the onDraw
to remove the circles and instead to render the lines we have plotted in our path:
and with that, we have a very basic painting app that looks like:
Efficient Drawing with Bitmap Cache
When drawing onto a canvas, you can often significantly improve render times by caching the image into a bitmap as outlined in this stackoverflow post.
This is a common pattern for improving drawing performance.
Reference for SimpleDrawingView
The full source code for our SimpleDrawingView
:
Drawing with Density Independent Pixels
When drawing or animating, you often want to draw using density independent pixels in order to be robust to different device sizes and densities. You may also want to determine the device height or width in order to draw intelligently. Copy this DeviceDimensionsHelper.java utility class to DeviceDimensionsHelper.java
in your project and use anywhere that you have a context to determine screen dimensions or do translations between dp
and px
:
You can then use this to do smarter drawing for more responsive custom views.
Cocktail and Canvas is bringing our popular step by step painting classes directly to you with our Paint at Home Kits! We ship our Paint Kits nationwide! Right now save 30% off our entire website ~PLUS~ buy any 3 of our Pre-Recorded or Written Instruction Paint Kits - Get 1 FREE!
What We Offer:
LIVE & INTERACTIVE Virtual Paint Classes - Now you can paint and socialize with your friends or even make new ones all from the comfort from your home! At this live class you'll be able to converse directly with the instructor and ask questions while you paint. We'll provide you with a supply kit that has everything you will need to recreate any of our beautiful paintings. Available with or without a supply kit.
LIVE & INTERACTIVE PRIVATE Virtual Paint Classes - Get a group of your friends or colleagues to paint remotely together! Choose your own date, time and painting! Only 5 people minimum requirement! Contact us at info@cocktailandcanvas.com to set up your party or for more information!
Recorded Virtual Paint Classes - Paint at your own pace with our pre-recorded, Virtual Paint Classes! This is a great option if you are unable to make our live classes or if you prefer to take your time or pause while you paint. Available with or without a supply kit
Written Instruction Paint Classes- This is a great option if you prefer to avoid using technology and want to dive straight into painting! This also a budget friendly option!
Absolutely NO experience is necessary to have a great time! We provide all the paint, canvases, brushes and easels along with an enthusiastic and entertaining artist who will lead you through a step-by-step process of recreating one of our many featured artworks. Come hang with us and “GET YOUR PAINT ON!”
Paint And Canvas Kit
We invite you to view our vast collection of Paint at Home Kits and our upcoming Live & Interactive Virtual Classes, choose the painting or class you would like to do and register today! We are a great option for date night, ladies night, an evening with friends, family, or co-workers or kids parties.
Amazon Canvas For Painting
If you are in the Phoenix area, you can also book an in-person private party with us! We offer a mobile service where we bring the party to you. We are a great choice for birthday parties, bachelorette parties, bridal and baby showers, family reunions, office parties, sorority functions, theme parties, team parties, fundraisers, charities, team building events, and corporate functions! Please contact us with your questions and requests!
Follow us on Facebook!
Follow us on Instagram!
info@cocktailandcanvas.com
Call or Text us at 702-467-2859