[ad_1]
RasmView is an Android drawing library; it supplies a view that permits customers to attract on prime of a bitmap.
Demo
https://www.youtube.com/watch?v=8qYhwjleT_8
Options
- 8 already outlined brushes, and you’ll outline your individual.
- Drawing on prime of pictures.
- Undo/redo operations.
- Zooming in/out, rotation & translation.
- Customized background coloration.
Obtain
Gradle:
dependencies {
implementation 'com.raedapps:rasmview:1.2.0'
}
Maven:
<dependency>
<groupId>com.raedapps</groupId>
<artifactId>rasmview</artifactId>
<model>1.2.0</model>
</dependency>
Utilization Information
Add the next to your structure file:
<com.raed.rasmview.RasmView
android:id="@+id/rasmView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
RasmContext
RasmContext
means that you can management the comb configuration, undo/redo, reset transformation, and extra. RasmContext
could be accessed from RasmView
:
val rasmView = findViewById<RasmView>(R.id.rasmView)
val rasmContext = rasmView.rasmContext
Altering the comb
You should utilize the BrushesRepository
to get an already outlined brush.
val brushesRepository = BrushesRepository(assets)
rasmContext.brushConfig = brushesRepository.get(Brush.Marker)
The next brushes are already outlined:
enum class Brush {
Pencil,
Pen,
Calligraphy,
AirBrush,
Marker,
HardEraser,
SoftEraser,
}
Brush coloration
Right here is how one can change the comb coloration:
rasmContext.brushColor = Coloration.RED
rasmContext.brushColor = 0xff2187bb.toInt() //ARGB
The alpha channel worth is ignored, you may management alpha by setting brushConfig.move
.
Brush measurement and different configurations
val brushConfig = rasmContext.brushConfig
brushConfig.measurement = 0.5f
brushConfig.move = 0.25f
brushConfig.isEraser = true
Customized brushes
val myStampBitmap = ...
val customBrushConfig = BrushConfig()
customBrushConfig.stamp = BrushStamp.BitmapStamp(myStampBitmap)
customBrushConfig.measurement = 0.25f
customBrushConfig.spacing = 0.1f
rasmContext.brushConfig = customBrushConfig
Drawing on a bitmap (your individual picture).
val imageBitmap = ... //load your bitmap whether or not from a URI or assets
rasmContext.setRasm(imageBitmap)
rasmView.resetTransformation()
Getting the drawing
val drawingBitmap = rasmContext.exportRasm()
Background coloration
rasmContext.setBackgroundColor(Coloration.BLACK)
Undo/redo
val rasmState = rasmContext.state
rasmState.undo()
rasmState.redo()
However you do not need to maintain your buttons enabled when an undo/redo will not be attainable, you may hearken 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
Enabling rotation
rasmContext.rotationEnabled = true
Resetting the transformation
rasmView.resetTransformation()
When you discovered a bug, please open a problem.
License
Copyright 2022 Raed Mughaus
Licensed below the Apache License, Model 2.0 (the "License");
you could not use this file besides in compliance with the License.
You could receive a replica of the License at
http://www.apache.org/licenses/LICENSE-2.0
Until required by relevant regulation or agreed to in writing, software program
distributed below the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, both specific or implied.
See the License for the precise language governing permissions and
limitations below the License.
[ad_2]
Source_link