简体   繁体   中英

How to crop the image within a print screen?

I am developing an application that chooses an image of a wound and displays it on the application screen. with this, the user marks the region of interest of the wound, so that later the algorithm can recognize and process the region of interest. I'm doing this using the lib implementation 'com.github.gcacace: signature-pad: 1.2.1' to demarcate the region and then I'm saving the screen's "printscreen" so I can save the markup along with the image of the wound. How I wish the image will look在此处输入图片说明

Exit: 在此处输入图片说明

However, I want to cut the printscreen according to the image of the wound to send to the server to process the image. Can someone help me cut out the wound image after marking.

    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 ""
}

I am still a learner so for an easy way to crop an image I would suggest using this library:

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

This is where you can crop the image as per your requirement and store the image on the server

As far as I know, I don't think it's possible to crop and image. In order to crop, you need to find the dimensions for the part that you want. I don't think you can tell the program the dimensions of what you want and then crop everything else off, as far as my knowledge goes. It might be possible to print an image, but I don't think Java can crop. Other coding programs might work better for this.

If you have the coordinates of the rectangle you want to save:

Bitmap croppedBmp = Bitmap.createBitmap(originalBmp, rectanglePositionX, rectanglePositionY, rectangleWidth, rectangleHeight);

Or you can try: BitmapFactory.decodeStream(InputStream is, Rect outPadding, Options opts) or BitmapFactory.decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts)

where in the Rect outPadding you will set the coordinates of the rectangle you want to save.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM