簡體   English   中英

如何在打印屏幕中裁剪圖像?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM