handle saving images with something drawn on them
This commit is contained in:
parent
b039a6f8d8
commit
7304234783
|
@ -295,6 +295,18 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
if (crop_image_view.isVisible()) {
|
||||
crop_image_view.getCroppedImageAsync()
|
||||
} else if (editor_draw_canvas.isVisible()) {
|
||||
val bitmap = editor_draw_canvas.getBitmap()
|
||||
if (saveUri.scheme == "file") {
|
||||
SaveAsDialog(this, saveUri.path, true) {
|
||||
saveBitmapToFile(bitmap, it, true)
|
||||
}
|
||||
} else if (saveUri.scheme == "content") {
|
||||
val filePathGetter = getNewFilePath()
|
||||
SaveAsDialog(this, filePathGetter.first, filePathGetter.second) {
|
||||
saveBitmapToFile(bitmap, it, true)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val currentFilter = getFiltersAdapter()?.getCurrentFilter() ?: return
|
||||
val filePathGetter = getNewFilePath()
|
||||
|
@ -610,15 +622,16 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
|
||||
override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
|
||||
if (result.error == null) {
|
||||
val bitmap = result.bitmap
|
||||
if (isCropIntent) {
|
||||
if (saveUri.scheme == "file") {
|
||||
saveBitmapToFile(result.bitmap, saveUri.path, true)
|
||||
saveBitmapToFile(bitmap, saveUri.path, true)
|
||||
} else {
|
||||
var inputStream: InputStream? = null
|
||||
var outputStream: OutputStream? = null
|
||||
try {
|
||||
val stream = ByteArrayOutputStream()
|
||||
result.bitmap.compress(CompressFormat.JPEG, 100, stream)
|
||||
bitmap.compress(CompressFormat.JPEG, 100, stream)
|
||||
inputStream = ByteArrayInputStream(stream.toByteArray())
|
||||
outputStream = contentResolver.openOutputStream(saveUri)
|
||||
inputStream.copyTo(outputStream)
|
||||
|
@ -636,12 +649,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
}
|
||||
} else if (saveUri.scheme == "file") {
|
||||
SaveAsDialog(this, saveUri.path, true) {
|
||||
saveBitmapToFile(result.bitmap, it, true)
|
||||
saveBitmapToFile(bitmap, it, true)
|
||||
}
|
||||
} else if (saveUri.scheme == "content") {
|
||||
val filePathGetter = getNewFilePath()
|
||||
SaveAsDialog(this, filePathGetter.first, filePathGetter.second) {
|
||||
saveBitmapToFile(result.bitmap, it, true)
|
||||
saveBitmapToFile(bitmap, it, true)
|
||||
}
|
||||
} else {
|
||||
toast(R.string.unknown_file_location)
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.pro.views
|
|||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
|
@ -125,4 +126,12 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
|
|||
backgroundBitmap = bitmap
|
||||
invalidate()
|
||||
}
|
||||
|
||||
fun getBitmap(): Bitmap {
|
||||
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawColor(Color.WHITE)
|
||||
draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue