![](/img/trans.png)
[英]How to crop the screen visible portion of an image from image view and store it?
[英]How to crop the image within a print screen?
我正在开发一个应用程序,该应用程序选择伤口图像并将其显示在应用程序屏幕上。 以此,用户标记伤口的感兴趣区域,以便稍后算法可以识别和处理感兴趣区域。 我正在使用 lib 实现 'com.github.gcacace: signature-pad: 1.2.1' 来划分区域,然后保存屏幕的“printscreen”,这样我就可以将标记与图像一起保存伤口。 我希望图像看起来如何
但是,我想根据伤口的图像剪切打印屏幕以发送到服务器以处理图像。 谁能帮我剪下标记后的伤口图像。
private fun saveImage(myBitmap: Bitmap?): String? {
try {
// image naming and path to include sd card appending name you choose for file
val mPath = Environment.getExternalStorageDirectory().toString() + "/imagesignature.jpg"
// create bitmap screen capture
val v1 = window.decorView.rootView
v1.isDrawingCacheEnabled = true
val bitmap = Bitmap.createBitmap(v1.drawingCache)
v1.isDrawingCacheEnabled = false
val imageFile = File(mPath)
val outputStream = FileOutputStream(imageFile)
val quality = 100
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream)
outputStream.flush()
outputStream.close()
//setting screenshot in imageview
val filePath = imageFile.path
val ssbitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
imagem.setImageBitmap(ssbitmap)
} catch (e: Throwable) {
// Several error may come out with file handling or DOM
e.printStackTrace()
}
return ""
}
我仍然是一个学习者,所以为了一种简单的裁剪图像的方法,我建议使用这个库:
https://github.com/ArthurHub/Android-Image-Cropper
您可以在此处根据需要裁剪图像并将图像存储在服务器上
据我所知,我认为裁剪和图像是不可能的。 为了裁剪,您需要找到所需零件的尺寸。 据我所知,我认为你不能告诉程序你想要什么的尺寸,然后裁剪掉其他所有东西。 可能可以打印图像,但我认为 Java 不能裁剪。 其他编码程序可能对此效果更好。
如果您有要保存的矩形的坐标:
Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, rectanglePositionX, rectanglePositionY, rectangleWidth, rectangleHeight);
或者您可以尝试: BitmapFactory.decodeStream(InputStream is, Rect outPadding, Options opts)
或BitmapFactory.decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts)
在 Rect outPadding 中,您将设置要保存的矩形的坐标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.