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