Verhelst
Verhelst

Reputation: 1503

Automatically crop image boundaries

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.sstatic.net/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).

Upvotes: 1

Views: 4041

Answers (2)

Håvard Geithus
Håvard Geithus

Reputation: 5613

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?

Upvotes: 1

P Varga
P Varga

Reputation: 20229

Look into Bitmap.createBitmap.

Upvotes: 0

Related Questions