GithubHelp home page GithubHelp logo

rufenkhokhar / drawingview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raed-mughaus/drawingview

0.0 0.0 0.0 595 KB

RasmView is an Android drawing view; it provides a view that allows users to draw on top of a bitmap.

License: Apache License 2.0

Kotlin 100.00%

drawingview's Introduction

RasmView

RasmView is an Android drawing library; it provides a view that allows users to draw on top of a bitmap.

Demo

https://www.youtube.com/watch?v=8qYhwjleT_8

Screenshot

Features

  • 8 already defined brushes, and you can define your own.
  • Drawing on top of images.
  • Undo/redo operations.
  • Zooming in/out, rotation & translation.
  • Custom background color.

Download

Gradle:

dependencies {
  implementation 'com.raedapps:rasmview:1.2.0'
}

Maven:

<dependency>
  <groupId>com.raedapps</groupId>
  <artifactId>rasmview</artifactId>
  <version>1.2.0</version>
</dependency>

Usage Guide

Add the following to your layout file:

<com.raed.rasmview.RasmView
  android:id="@+id/rasmView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  />

RasmContext

RasmContext allows you to control the brush configuration, undo/redo, reset transformation, and more. RasmContext can be accessed from RasmView:

val rasmView = findViewById<RasmView>(R.id.rasmView)
val rasmContext = rasmView.rasmContext

Changing the brush

You can use the BrushesRepository to get an already defined brush.

val brushesRepository = BrushesRepository(resources)
rasmContext.brushConfig = brushesRepository.get(Brush.Marker)

The following brushes are already defined:

enum class Brush {
    Pencil,
    Pen,
    Calligraphy,
    AirBrush,
    Marker,
    HardEraser,
    SoftEraser,
}

Brush color

Here is how to change the brush color:

rasmContext.brushColor = Color.RED
rasmContext.brushColor = 0xff2187bb.toInt() //ARGB

The alpha channel value is ignored, you can control alpha by setting brushConfig.flow.

Brush size and other configurations

val brushConfig = rasmContext.brushConfig
brushConfig.size = 0.5f
brushConfig.flow = 0.25f
brushConfig.isEraser = true

Custom brushes

val myStampBitmap = ...
val customBrushConfig = BrushConfig()
customBrushConfig.stamp = BrushStamp.BitmapStamp(myStampBitmap)
customBrushConfig.size = 0.25f
customBrushConfig.spacing = 0.1f
rasmContext.brushConfig = customBrushConfig

Drawing on a bitmap (your own image)

val imageBitmap = ... //load your bitmap whether from a URI or resources
rasmContext.setRasm(imageBitmap)
rasmView.resetTransformation() 

Getting the drawing

val drawingBitmap = rasmContext.exportRasm()

Background color

rasmContext.setBackgroundColor(Color.BLACK)

Undo/redo

val rasmState = rasmContext.state
rasmState.undo()
rasmState.redo()

But you do not want to keep your buttons enabled when an undo/redo is not possible, you can listen to state updates:

undoButton.setOnClickListener {
    rasmState.undo()
}
redoButton.setOnClickListener {
    rasmState.redo()
}
rasmState.addOnStateChangedListener {
    undoButton.isEnabled = rasmState.canCallUndo()
    redoButton.isEnabled = rasmState.canCallRedo()
}
undoButton.isEnabled = rasmState.canCallUndo()
redoButton.isEnabled = rasmState.canCallRedo()

Clearing the drawing

rasmContext.clear()

Enabling rotation

rasmContext.rotationEnabled = true

Resetting the transformation

rasmView.resetTransformation()

License

Copyright 2022 Raed Mughaus

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.

drawingview's People

Contributors

raed-mughaus avatar

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.