A view that allows to paint and saves the result as a bitmap

Related tags

UI/UX DrawableView
Overview

Android Drawable View

Android Arsenal Maven Central

Logo

Sample app:

An Android view that allows to paint with a finger in the screen and saves the result as a Bitmap.

Importing to your project

Add this dependency to your build.gradle file:

dependencies {
    compile 'me.panavtec:drawableview:{Lib version, see the mvn central badge}'
}

Basic usage

Add the view to your xml layout in this way:

<me.panavtec.drawableview.DrawableView
        android:id="@+id/paintView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Now in your activity code set a config to this view:

DrawableViewConfig config = new DrawableViewConfig();
config.setStrokeColor(getResources().getColor(android.R.color.black));
config.setShowCanvasBounds(true); // If the view is bigger than canvas, with this the user will see the bounds (Recommended)
config.setStrokeWidth(20.0f);
config.setMinZoom(1.0f);
config.setMaxZoom(3.0f);
config.setCanvasHeight(1080);
config.setCanvasWidth(1920);
drawableView.setConfig(config);

Now the view is ready to paint! You can see the attached sample for more info

To save the results of the view to a Bitmap just call:

java drawableView.obtainBitmap()

ChangeLog

0.6

[Bug/Improvement] When the view is bigger than the canvas (config width/height) now I'm showing a rect and don't allow user to draw outside the canvas.

[Improvement] Added obtainBitmap(Bitmap method) to draw inside an already created Bitmap

0.5

Initial version

Developed by

Christian Panadero Martinez - http://panavtec.me - @PaNaVTEC

Carlos Morera de la Chica - @CarlosMChica

License

Copyright 2015 Christian Panadero Martinez

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Setting canvas height

    Setting canvas height

    Hi again! I cannot seem to find a way to limit the height of where the user can draw on the view. I've set the height of the drawable view to be wrap content and match parent both allow drawing height to be the height of the device. What I need to do is allowing drawing only over the height of a picture that I have loaded onto the same view and I have the height of that picture and I've set it to canvasHeight of the config but I am still able to draw all along the height of the whole device. I have also tried manually setting the canvasHeight to be 200 for example of 50, still able to draw all over the height.

    Check this code please, this is just inside an Activity that has an imageView and a drawableView inside it, nothing else. setting canvasWidth works just fine by the way, I am not able to move the canvas to the right because the width is as just as the width of the device

    
            DisplayMetrics displaymetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
            int width = displaymetrics.widthPixels;
    
            final DrawableViewConfig config = new DrawableViewConfig();
            config.setStrokeColor(getResources().getColor(android.R.color.white));
            config.setStrokeWidth(20.0f);
            config.setMinZoom(1.0f);
            config.setMaxZoom(1.0f);
            config.setCanvasWidth(width);
    
    bookmarkIMG.getViewTreeObserver().addOnPreDrawListener(
                    new ViewTreeObserver.OnPreDrawListener() {
                        public boolean onPreDraw() {
    
                            int height = bookmarkIMG.getMeasuredHeight();
    
                            config.setCanvasHeight(height);
    
                            Log.d("SIZE", "Canvas size set to " + height); 
    
                            return true;
                        }
                    });
    
            drawableView.setConfig(config);
    

    Thanks so much for your help so far!

    bug question 
    opened by Odaym 12
  • obtainBitmap() not returning the drawn image

    obtainBitmap() not returning the drawn image

    I use the drawableView to draw something and it works fine and everything but when I want to grab the bitmap from the drawableView I do not get the bitmap back correctly.

    I have verified this by saving the bitmap from obtainBitmap() into a file on the device and uploaded to dropbox to see the picture. The file always has the size of 0.91 KB and consists of a rectangular, background-less area.

    If you want, here's a link to the image, it's empty of course but you can save it and check the size and how the predefined rectangular shape is there: http://i.imgur.com/0EZn7Gz.png

    Any ideas? Thanks!

    wontfix 
    opened by Odaym 9
  • Can't draw if dragging finger horizontally

    Can't draw if dragging finger horizontally

    Tested this on Galaxy S3 and Nexus 5. I cannot seem to be able to draw if I start dragging my finger horizontally when trying to draw anything, the line barely starts and then it cuts off every time. I can draw just fine if I drag diagonally or vertically and that's perfectly fine.

    Configuration while facing this (I have 1 and 1 set for Min/Max zoom because I don't want to enable any zoom ability):

    config.setStrokeColor(getResources().getColor(android.R.color.white));
                config.setStrokeWidth(20.0f);
                config.setMinZoom(1.0f);
                config.setMaxZoom(1.0f);
                config.setCanvasWidth(4000);
                config.setCanvasHeight(4000);
    
    wontfix 
    opened by Odaym 5
  • Pinch-zoom on view makes drawing disappear

    Pinch-zoom on view makes drawing disappear

    As the title suggests, when you've drawn some things on the view and then you pinch to zoom, if the Max/Min Zoom levels are set to 0 and 0, the view instantly disappears and you cannot get it back or draw anymore.

    If the levels are set to 3.0 and 1.0 as you provided in the example, the view zooms in for a second and then disappears and you cannot get it back or draw anymore.

    Also, when beginning to draw, sometimes the draw command doesn't go through and only leaves a little scratch drawn, then you have to press again and also does the same thing. Until you rapidly move your finger and then the thing starts to work fine, but also mid-drawing you can cause it to do that scratch issue again.

    Any suggestions? This is just from the first 10 minutes of me trying this library, really great work by the way, much needed and so easy to use!

    bug 
    opened by Odaym 4
  • [SOLVED] Black Image in saved bitmap

    [SOLVED] Black Image in saved bitmap

    Hey, the method obtaindBitmap() returns Bitmap. But, when I try save file, his saved such as whole black image. In some google searches, I discovered which background color android to JPG file is black and the default color stroke is black too.

    So, to show image correctly, the way was change JPG background color. The code below ""fixes"" this.

    I hope help someone.

    Bitmap bitmap = drawableView.obtainBitmap();
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(drawableView.obtainBitmap(), 0, 0, null);
    FileOutputStream fOut = null;
    try {
              String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
              String mImageName = "MI_" + timeStamp + ".jpg";
              fOut = new FileOutputStream (new File(getGalleryPath(), mImageName), true);
              bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
              fOut.flush();
              fOut.close();
    } catch (FileNotFoundException e) {
              e.printStackTrace();
    } catch (IOException e) {
               e.printStackTrace();
    }
    
    private static String getGalleryPath() {
            return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/Camera";
    }
    
    opened by ygorreis 3
  • appear  android.os.BadParcelableException  error

    appear android.os.BadParcelableException error

    Caused by: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class java.util.ArrayList at android.os.Parcel.readParcelableCreator(Parcel.java:2114) at android.os.Parcel.readParcelable(Parcel.java:2055) at android.view.AbsSavedState.(AbsSavedState.java:57) at android.view.View$BaseSavedState.(View.java:19038)

    opened by hfbi360 2
  • setBackgroundColor does not have an effect on the obtained bitmap

    setBackgroundColor does not have an effect on the obtained bitmap

    Hi!

    I'm using DrawableView, and I set the background color to white. This does make the background white while I'm drawing, but when I call obtainBitmap I get a black background. Is this expected? If so, how can I make the 'real' background white

    opened by geeeeoffff 2
  • Parcelable protocol requires that the class implements Parcelable

    Parcelable protocol requires that the class implements Parcelable

    When the onRestoreInstanceState function callbacks, a BadParcelableException is thrown. I tried to solve it in the following way. in DrawableView,

    @Override
     protected Parcelable onSaveInstanceState() {
         Parcelable parcelable = super.onSaveInstanceState();
         Bundle bundle = new Bundle();
         bundle.putParcelable("super_data", parcelable);
         DrawableViewSaveState state = new DrawableViewSaveState();
         state.setPaths(paths);
         bundle.putParcelable("path_data", state);
         return bundle;
     }
    
    @Override
     protected void onRestoreInstanceState(Parcelable state) {
         if (state instanceof Bundle) {
             Bundle bundle = (Bundle) state;
             DrawableViewSaveState saveState = bundle.getParcelable("path_data");
             if (saveState != null) {
                 paths.addAll(saveState.getPaths());
                 for (SerializablePath p : paths) {
                     p.loadPathPointsAsQuadTo();
                 }
             }
             Parcelable superData = bundle.getParcelable("super_data");
             super.onRestoreInstanceState(superData);
         } else {
             super.onRestoreInstanceState(state);
         }
     }
    
    

    new DrawableViewSaveState,

    public class DrawableViewSaveState implements Parcelable {
    
        private ArrayList<SerializablePath> paths;
    
        public ArrayList<SerializablePath> getPaths() {
            return paths;
        }
    
        public void setPaths(ArrayList<SerializablePath> paths) {
            this.paths = paths;
        }
    
        @Override
        public int describeContents() {
            return 0;
        }
    
        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeList(this.paths);
        }
    
        public DrawableViewSaveState() {
        }
    
        protected DrawableViewSaveState(Parcel in) {
            this.paths = new ArrayList<SerializablePath>();
            in.readList(this.paths, SerializablePath.class.getClassLoader());
        }
    
        public static final Creator<DrawableViewSaveState> CREATOR = new Creator<DrawableViewSaveState>() {
            @Override
            public DrawableViewSaveState createFromParcel(Parcel source) {
                return new DrawableViewSaveState(source);
            }
    
            @Override
            public DrawableViewSaveState[] newArray(int size) {
                return new DrawableViewSaveState[size];
            }
        };
    }
    
    opened by woilsy 0
  • Referenced class is missing

    Referenced class is missing

    DrawerDelegate references a class which is not present causing following exception: me.panavtec.drawableview.gestures.DrawerDelegate: can't find referenced class me.panavtec.drawableview.internal.SerializablePath

    opened by mwajeeh 0
  • Disable Touch Listener

    Disable Touch Listener

    I'm using this Gradel in photo editor type app. I'm inflating this view above image view. is it possible to handle setConfig. I want that it will work when I click on the particular button and it will be disabled when I click on another view.

    opened by sovoereign 0
  • :(

    :(

    Caused by: android.os.BadParcelableException: at android.os.Parcel.readParcelableCreator(Parcel.java:2511) at android.os.Parcel.readParcelable(Parcel.java:2462) at android.view.AbsSavedState.(AbsSavedState.java:67) at android.view.View$BaseSavedState.(View.java:22761) at android.view.View$BaseSavedState.(View.java:22750) at me.panavtec.drawableview.DrawableViewSaveState.(DrawableViewSaveState.java:14) at me.panavtec.drawableview.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:40) at me.panavtec.drawableview.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:38) at android.os.Parcel.readParcelable(Parcel.java:2471) at android.os.Parcel.readValue(Parcel.java:2365) at android.os.Parcel.readSparseArrayInternal(Parcel.java:2813) at android.os.Parcel.readSparseArray(Parcel.java:2068) at android.os.Parcel.readValue(Parcel.java:2422) at android.os.Parcel.readArrayMapInternal(Parcel.java:2732) at android.os.BaseBundle.unparcel(BaseBundle.java:269) at android.os.Bundle.getSparseParcelableArray(Bundle.java:934) at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2104) at android.app.Activity.onRestoreInstanceState(Activity.java:1074) at android.app.Activity.performRestoreInstanceState(Activity.java:1029) at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1175) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2638)

    opened by oPrisonbreak 1
Owner
Christian Panadero
Christian Panadero
A View on which you can freely draw, customizing paint width, alpha and color, and take a screenshot of the content. Useful for note apps, signatures or free hand writing.

FreeDrawView A View that let you draw freely on it. You can customize paint width, alpha and color. Can be useful for notes app, signatures or hands-f

Riccardo Moro 643 Nov 28, 2022
Android view that allows the user to create drawings. Customize settings like color, width or tools. Undo or redo actions. Zoom into DrawView and add a background.

DrawView Android view that allows the user to create drawings. Draw anything you like in your Android device from simple view. Customize draw settings

Oscar Gilberto Medina Cruz 839 Dec 28, 2022
Android-ScrollBarPanel allows to attach a View to a scroll indicator like it's done in Path 2.0

Path 2.0 like ScrollBarPanel for Android Android-ScrollBarPanel allows to attach a View to a scroll indicator like it's done in Path 2.0. Features Sup

Arnaud Vallat 551 Dec 22, 2022
Android View for displaying and selecting values in a circle-shaped View, with animations and touch gestures.

CircleDisplay Android View for displaying and selecting (by touch) values / percentages in a circle-shaped View, with animations. Features Core featur

Philipp Jahoda 287 Nov 18, 2022
FloatingView can make the target view floating above the anchor view with cool animation

FloatingView FloatingView can make the target view floating above the anchor view with cool animation Links 中文版 README Blog about FloatingView demo.ap

UFreedom 1.8k Dec 27, 2022
用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View.

PathAnimView 用于做Path动画的自定义View。 I have a path.I have a view. (Oh~),Path(Anim)View. 现已经找到图片->SVG->PATH的正确姿势, Now i have a pic.I have a view. Oh~,Path(A

张旭童 1.1k Oct 28, 2022
The CustomCalendarView provides an easy and customizable calendar to create a Calendar. It dispaly the days of a month in a grid layout and allows to navigate between months

Custom-Calendar-View To use the CustomCalendarView in your application, you first need to add the library to your application. You can do this by eith

Nilanchala Panigrahy 113 Nov 29, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
💳 CreditCardView is an Android library that allows developers to create the UI which replicates an actual Credit Card.

CreditCard View CreditCardView is an Android library that allows developers to create the UI which replicates an actual Credit Card. Displaying and en

Vinay Gaba 769 Dec 14, 2022
IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts.

IconicDroid IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts. Try out the sample application on the Googl

Artur Termenji 387 Nov 20, 2022
Allows you to launch various /hidden/ options of the Oculus Quest (2)

vrLauncher Allows you to launch various /hidden/ options of the Oculus Quest (2) Using it Sideload the apk onto your Oculus Quest (2) Choose the optio

Bastian 153 Dec 25, 2022
Drawing App: A simple drawing application that allows the user to draw using a pencil or using shapes

Drawing-App Drawing app is a simple drawing application that allows the user to

Nada Feteiha 1 Oct 5, 2022
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.

This project isn't maintained anymore. It is now recommended to use https://github.com/peterLaurence/MapView. MapView is maintained by Peter, one of o

Mike Dunn 1.5k Dec 29, 2022
Snake View is a simple and animated linear chart for Android.

Snake View Snake library is a simple and animation line chart for Android. Latest Version How to use Configuring your project dependencies Add the lib

Txus Ballesteros 339 Dec 14, 2022
A simple, customizable and easy to use swipeable view stack for Android.

SwipeStack A simple, customizable and easy to use swipeable view stack for Android. QuickStart Include the Gradle dependency dependencies { compil

Frederik Schweiger 1.5k Dec 30, 2022
A simple library to let you sign (or draw lines) smoothly with your finger into a view and save it.

FingerSignView Introduction FingerSignView is a simple library that lets you finger, or draw lines, smoothly with your finger into a View and save it

Agnaldo Pereira 25 Nov 20, 2022
Simple View to change Brush Size, Alpha and Color

BrushView Simple View to change Brush Size, Alpha and Color Screenshots How to install In your build.gradle project allprojects { repositories {

Andres Ruiz 16 Jun 28, 2018
💳 A quick and easy flip view through which you can create views with two sides like credit cards, poker cards etc.

The article on how this library was created is now published. You can read it on this link here. →. ?? EasyFlipView Built with ❤︎ by Wajahat Karim and

Wajahat Karim 1.3k Dec 14, 2022
A simple and customizable two or three states Switch View

RMSwitch A simple View that works like a switch, but with more customizations. With the option to choose between two or three states. (from v1.1.0) **

Riccardo Moro 656 Dec 2, 2022