Giter Site home page Giter Site logo

mukeshsolanki / drawingview-android Goto Github PK

View Code? Open in Web Editor NEW
237.0 10.0 53.0 1.26 MB

DrawingView is a simple view that lets you draw on screen using your fingers and lets you save the drawings as images.

License: MIT License

Java 100.00%
drawingview drawingview-android android gradle sketch draw

drawingview-android's Introduction

DrawingView-Android - deprecated



This library has been deprecated in favor of https://github.com/akshay2211/DrawBox DrawingView is a simple view that lets you draw on screen using your fingers and lets you save the drawings as images.

Demo

Getting started

Its really simple to integrate DrawingView in android. All you need to do make the following change to you build gradle.

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.mukeshsolanki:DrawingView-Android:<latest-version>'
}

How to use DrawingView

Its fairly simple and straight forward to use DrawingView in you application. Just add the following in your layout where you want to display the DrawingView.

<com.mukesh.DrawingView
  android:id="@+id/scratch_pad"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_above="@+id/buttons"
  />

and reference it in your activity/fragment and assign the DrawingView like wise.

DrawingView drawingView = (DrawingView) findViewById(R.id.scratch_pad);
drawingView.initializePen(); //To use the pen mode to draw on the screen
drawingView.initializeEraser(); //To use the eraser mode to clear the screen
drawingView.setBackgroundColor(@ColorInt int color); //To set the background color of the drawing view
drawingView.setEraserSize(float size); //To set the size of the eraser
drawingView.setPenSize(float size); //To set the size of the pen
drawingView.setPenColor(@ColorInt int color); //To set the color of the pen
drawingView.saveImage(String filePath, String filename, Bitmap.CompressFormat format, int quality); //To save the image after your done drawing
drawingView.loadImage(Bitmap bitmap); //Load image (your saved drawing)
drawingView.clear(); //clear image

Author

Maintained by Mukesh Solanki

Contribution

GitHub contributors

License

MIT License

Copyright (c) 2018 Mukesh Solanki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

drawingview-android's People

Contributors

arminghm avatar hcz017 avatar mukeshsolanki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drawingview-android's Issues

NullPointerException when using setBackgroundColor()

I'm trying to set the background color to black, but it throws a NullPointerException.

This is my code:

DrawingView drawingView = (DrawingView) findViewById(R.id.scratch_pad);
drawingView.initializePen();
drawingView.setPenColor(Color.WHITE);
drawingView.setBackgroundColor(Color.BLACK);

And this is the stacktrace:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawColor(int)' on a null object reference
                  at com.mukesh.DrawingView.setBackgroundColor(DrawingView.java:156)
                  at com.coolioasjulio.draw.MainActivity.onCreate(MainActivity.java:21)
                  at android.app.Activity.performCreate(Activity.java:6955)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
                  at android.app.ActivityThread.-wrap14(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6776) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

I did some digging around, and it seems that mCanvas is null, resulting in a NullPointerException.

How can I fix this?

Colors issue

I don't know what's going on here, but it seems like there's white color over red. Is there any way to fix it?
Screenshot_2021-03-07-20-04-09-151_com get it bro paint

Error

Install android:

Erro --> Failed to resolve: com.github

implementation 'com.github.mukeshsolanki:DrawingView-Android:<latest-version>'

Please help to implement undo redo in app level.

Subject of the issue

Describe your issue here.

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working demo.

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

high cpu usage causes app to crash

The code is really great , but CPU usage is very high for a simple app, making it really slow and causes app to crash some times , If this can be improved it will be really useful, In android studio the app showed a CPU usage of 40 percent , really high .

Color picker issue

Hi,
Your DrawingView repository is really amazing and helps a lot for the development of an educative app for children where I'm completing an internship.
I was just wondering if it is normal that when you chose another colour while drawing, a white overlay overrides the colour line.
This happens only when the pen is moving. So when you just tap with the pen the colour is correctly used.
On the screenshot:

  1. Regular pen without colour picked
  2. Color picked and draw a line
  3. Color picked and tapped simple dots

screenshot_20180408-122236

May you help me with this issue?
Kind regards,
Hendrik

initializePen() metod doesn't work

initializePen(); method doesn't work after initializeEraser(); called

Example:
In case of user clicked on Eraser button and then on Pen button, view still set in Eraser mode.

package com.diezgames.drawrailwaycarriage;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.mukesh.DrawingView;

public class NewRailwayCarriageDrawer extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_railway_carriage_drawer);
    final DrawingView drawingView = (DrawingView) findViewById(R.id.scratch_pad);
    final Button drawPenBtn = (Button) findViewById(R.id.draw_c_pen);
    final Button drawEraseBtn = (Button) findViewById(R.id.draw_c_erase);
    drawPenBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawingView.initializePen();
            drawingView.setPenSize(10.0f);
            Log.d(this.getClass().toString(), "On Pen Btn Clicked");
        }
    });
    drawEraseBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawingView.initializeEraser();
            drawingView.setEraserSize(10.0f);
            Log.d(this.getClass().toString(), "On Erase Btn Clicked");
        }
    });
}

}

Stroke is not fully opaque

Changing Color.RED with setAlpha(int) doesn't seem to have any effect. This is how the stroke looks on bright background.

screenshot_20170819221253

Undo and Redo

I would like to request an Undo and Redo functionality please

Use of an imageview and drawing on it and match

I want to use an imageview like "OK" in background and allow the user to draw on it and want to check if he draw nearly close (exactly same not needed) to the actual image and pass the verification gate.

Drawing over

First, thank you for the brilliant utility.
Just wondering if you could add a feature to load an image at the init of the drawingView. That will help enable draw on top of an image. Please let know. Thanks.

Saving image

Thanks so much for this great library. I'm having some trouble with the saveImage() method. I'm trying to save the image to my internal/local storage, but I'm not sure what to put my for my filePath parameter.

You use getExternalStorageDirectory() in your saveImage example, but I don't have an external storage location. When I do the following code in my onClick, it doesn't show up anywhere in my internal storage when I use my File Manager app: drawingView.saveImage(Environment.getExternalStorageDirectory().toString(), "test_tongue_image", Bitmap.CompressFormat.PNG, 100);

Thoughts on a simple way to save it locally?

Eracing using drawing history

Hi, is it possible to erace user's drawings step by step using drawing history? I mean that when user draw a line, is it possible to call some method which will erace it completely without using of eracer mode?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.