2

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 enter image description here

Exit: enter image description here

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 ""
}
Carlos Diego
  • 348
  • 5
  • 20

3 Answers3

5

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

Robert Foster
  • 2,317
  • 18
  • 28
Srikanth G
  • 80
  • 9
  • but I wanted this to be done implicitly by code, automatically and not the user who made this cut. The user only chooses the image and demarcates the region and sends it to the server, the app does the rest. – Carlos Diego Mar 07 '20 at 13:56
  • Srikanth G has the right idea. Use that as a base. If you want to go further and have the image cropped to a specific shape defined by the user, you will need to write the code for that yourself and merge it with the Android-Image-Cropper (in cropeShape). I could not find anything open source that does this for you. I know snapchat has this feature which it calls scissors. – Matt Roberts Mar 24 '20 at 14:06
4

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.

boi yeet
  • 86
  • 10
4

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.

kgmk
  • 71
  • 2
  • you can help me in https://stackoverflow.com/questions/61216402/how-to-improve-image-segmentation-using-the-watershed – Carlos Diego Apr 22 '20 at 14:29