2

我正在开发一个选择伤口图像并将其显示在应用程序屏幕上的应用程序。这样,用户就可以标记伤口的感兴趣区域,以便以后算法可以识别和处理感兴趣的区域。我正在使用 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 ""
}
4

3 回答 3

5

我仍然是一个学习者,所以为了方便地裁剪图像,我建议使用这个库:

https://github.com/ArthurHub/Android-Image-Cropper

在这里您可以根据需要裁剪图像并将图像存储在服务器上

于 2020-03-07T06:28:14.810 回答
4

据我所知,我认为不可能裁剪和成像。为了裁剪,您需要找到所需零件的尺寸。据我所知,我认为你不能告诉程序你想要什么的尺寸,然后剪掉其他所有东西。可能可以打印图像,但我认为 Java 不能裁剪。其他编码程序可能对此效果更好。

于 2020-03-17T23:30:44.503 回答
4

如果您有要保存的矩形的坐标:

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 中,您将设置要保存的矩形的坐标。

于 2020-03-23T19:59:43.507 回答