Visual Basic .Net find image on bitmap

FragReaper
FragReaper used Ask the Experts™
on
In code, I retrieve a bitmap that has been drawn with on a picturebox by the user. This drawing is a white background with black pen, and can be of any size within the bounds of the picturebox. What I need to do first is remove all the excess whitespace around the bitmap. The way I have been doing this has been to run an iteration through every pixel of the bitmap, looking for black, and recording these co-ordinates. With the bitmap being at least 300 x 120 pixels this iteration takes time, around 6 minutes on this PC. I need:

A) a more efficient way to find the useful part of the image on the bitmap.
B) a way to move this part of the image to a new bitmap
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Yuo can use  Bitmap.LockBits function . That function get data from bitmap to BitMapData and it is pointer based so it is much faster than normal image scanning.

you can find sample over here.

http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx
Most Valuable Expert 2012
Top Expert 2014
Commented:
I think a better approach would be to use graphics paths and keep storing those paths as well as drawing. This way, you can draw those paths again on a different bitmap. Its like vector graphics. Here are few examples of using graphicspath.

http://www.java2s.com/Code/VB/2D/CreateaGraphicsPathandDrawPath.htm

http://www.java2s.com/Code/VB/2D/Graphic-Path.htm

http://visualbasic.about.com/od/usingvbnet/a/GDIP06_2.htm

Author

Commented:
Thanks!

You gave me the idea to call a Sub that recorded the limits of the drawing as it was created, this meant I didn't have to process the image to find the unused space.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial