Link to home
Start Free TrialLog in
Avatar of FragReaper
FragReaper

asked on

Visual Basic .Net find image on bitmap

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
Avatar of jinal
jinal
Flag of India image

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
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FragReaper
FragReaper

ASKER

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.