Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 13-Feb-12 12:36pm
v2
Comments
BillWoodruff 10-Feb-12 18:41pm    
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 ?
EricThe 10-Feb-12 19:14pm    
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

1 solution

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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900