1

I'm looking for an automatic way to grab a piece of a bitmap and extract a certain part of it. Let me explain: If I have this image:butterfly https://i.stack.imgur.com/DsDwe.jpg

It has a big white border. (see link for better white result) I'm looking for a way to only grab the dialog above. So no white borders around the dialog. Is there a way to do this by code or with a library?

You should know that the image could have any form and positioned anywhere on the white dialog.

So a user draws something on the white panel and i need the program to automatically make a rectangle about where the users drew on the canvas and save that bitmap where the user drew on the canvas (Everything in between that rectangle).

Verhelst
  • 1,492
  • 2
  • 22
  • 46
  • Are you asking how you can identify the border that could be cut off? Or are you asking how to cut off the borders of given size? – Codo Jul 28 '12 at 14:52
  • I'm looking for a way to get only the dialog of the picture. So the picture is a big white bitmap and i need to extract the dialog from it. Note that the dialog can be positioned anywhere and could have any form. (circle, etc) It's always on a white background – Verhelst Jul 28 '12 at 14:54

2 Answers2

1

Pseudocode

  1. Define the background color.
  2. Scan from the left, right, bottom, top and store the locations of the transitions from background to drawing.
  3. The rectangle defined by (left, bottom) and (right, top) defines the cropping area

For a Java code example, please see: How to auto crop an image white border in Java?

Community
  • 1
  • 1
Håvard Geithus
  • 5,544
  • 7
  • 36
  • 51
0

Look into Bitmap.createBitmap.

P Varga
  • 19,174
  • 12
  • 70
  • 108
  • You should know that the image could have any form and positioned anywhere on the white dialog. – Verhelst Jul 28 '12 at 14:51
  • So a user draws something on the white panel and i need the program to automatically make a rectangle about where the users drew on the canvas and save that bitmap where the user drew on the canvas (Everything in between that rectangle). – Verhelst Jul 28 '12 at 14:59
  • I don't think Android contains anything by default which would aid in this, although you could check pixel-by-pixel from each side until you found a non-white pixel, and then use `createBitmap` to crop. But ideally someone knows of a Java autocropping library. – P Varga Jul 28 '12 at 15:53