【问题标题】:How to crop the image within a print screen?如何裁剪打印屏幕内的图像?
【发布时间】:2020-03-06 19:47:36
【问题描述】:

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

【问题讨论】:

  • 您只需要截取屏幕截图的较小版本吗?这是你的问题吗?

标签: java android kotlin mobile


【解决方案1】:

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

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

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

【讨论】:

  • 但我希望这可以通过代码隐式完成,而不是由进行此剪辑的用户自动完成。用户只需选择图像并划定区域并将其发送到服务器,其余的由应用程序完成。
  • Srikanth G 的想法是正确的。以此为基础。如果您想进一步将图像裁剪为用户定义的特定形状,则需要自己编写代码并将其与 Android-Image-Cropper(在cropeShape 中)合并。我找不到任何可以为您执行此操作的开源代码。我知道 snapchat 有这个叫做剪刀的功能。
【解决方案2】:

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

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

【讨论】:

【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 2016-10-13
    相关资源
    最近更新 更多