Click here to Skip to main content

Removing Boundaries From Image

Sign Up to vote bad
good
Hello Everybody
I have an image that has some text but it has white margins, i am trying to figure out how to remove the gargins from that image so image has just the text
Thanks for answering
Posted 13 Feb '12
Edited 13 Feb '12

Comments
BillWoodruff - 10 Feb '12
Please clarify your question. And tag it with WinForms, WPF, or whatever you are developing it in. By "margins" do mean to say there is a white border color area surrounding all, or some, sides of the image ? In that case: the problem is how to crop the image. When you say "margins:" do you mean there is a white border around the Text; or, do you mean that the text is on a white background that, because it extends outside the area in which the Text is, gives the appearance of white margins ? Is this image made up of only two elements: text in one color, and the rest in white ? Or, is the text, with white background, or margins, part of some larger image: and you want to remove the white background, or margins, only from the text ? Are you saying that you wish to remove ALL white color from the whole image ? Your clear descriptions of these question can help choose a good strategy. If the image is not large, why not post a link to it ?
ibnkhaldun - 10 Feb '12
Yes it is an image with text, text is in black background is white and it is about 15 pixel of white border all around that needs to be cropped. I wanted to upload the image but didnt find option to upload the image. Thanks for your reply

Assume you have Windows Forms Project open, and PictureBox on the Form.
 
1. for this solution you might use this image[^], which is a 200x100px .png file (no transparency) on which white text appears on a black background, and there is an "interior border" 15 pixels thick on all sides of the image.
 
2. set the above image to be the PictureBox's Image.
 
3. set the 'SizeMode of the PictureBox to 'CenterImage.
 
4. now calculate the actual part of the image you wish displayed : since you wish to crop 15 pixels around the whole image: it will be 30 pixels less in height, 30 pixels less in width: so set the PictureBox size to to 170x70.
 
5. now run your project: observe the white margin is cropped.
 
In other circumstances, more complex solutions may be required where you actually have to go through Graphics operations.
 
And, of course, the simplest solution of all is to crop the image in some simple image editor before you use it ... but ... if you want to show the white margin sometimes, but hide it other times, you can still achieve this by simply changing the size of the PictureBox.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

add
  Print Answers RSS
Your Filters
Interested
Ignored
     
  1. OriginalGriff (1,245)
  2. Sandeep Mewara (1,037)
  3. VJ Reddy (545)
  4. SAKryukov (473)
  1. Sandeep Mewara (13,934)
  2. OriginalGriff (12,986)
  3. SAKryukov (8,004)
  4. VJ Reddy (5,145)
  5. losmac (5,065)


Advertise | Privacy | Mobile
Web02 | 2.5.120515.1 | Last Updated 13 Feb 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid