tags:

views:

236

answers:

3

I have an idea and maybe you guys can give me a good start or an idea in which path might be correct.

I have a picturebox right now loading a specific bmp file. What I want to do is load this bmp file into the picturebox and then load another picture on top of it. The kicker to this all is the 2nd picture must be drawn. The 2nd picture is just a fill in black box. This black box must also overlay on the first image exactly right, the black box has cordinates from paint on it (yes we have the # of the cordaints).

Still think the picturebox is the way to go, or is there a way to load paint into this, and then paint on top of the paint image?

1) Need to load an image 2) Need to read a specific file that has cords 3) Need to draw a black rectangle that matches those coords (Those cords were created in paint).

What do you think the best way to approach this is? A Picture box with code to draw in the cords of the redacted image

A: 

This answer is written to apply to both web and non-web uses of C# (why I did not give specific examples.)

GDI and other graphics libs all have functions that will paint a filled rectangle on top of an image. This is the way to go. If you use two images there is a good chance for a standard user and a great chance for a hacker they will be able to view just the original image, exposing the information you are trying to hide.

If you only send an image with the areas redacted, you will never have to worry about them being seen.

Hogan
The people who have access to this will need both the ability to see the box and the original image
Mike
ok... um... what exactly is your question again?
Hogan
i'll make a edit
Mike
A: 

Perhaps these links will help you:

http://www.bobpowell.net/pictureboxhowto.htm

http://www.bobpowell.net

Chris Dunaway
+1  A: 

Here's a code sample that should do what you're after:

//Load in an image
pbTest.Image = Image.FromFile("c:\\Chrysanthemum.jpg");

//Create the graphics surface to draw on
using (Graphics g = Graphics.FromImage(pbTest.Image))
{
    using (SolidBrush brush = new SolidBrush(Color.Black))
    {
        //Draw a black rectangle at some coordinates
        g.FillRectangle(brush, new Rectangle(0, 0, 20, 10));
        //Or alternatively, given some points
        //I'm manually creating the array here to prove the point, you'll want to create your array from your datasource.
        Point[] somePoints = new Point[] { new Point(1,1), new Point(20,25), new Point(35, 50), new Point(90, 100) };

        g.FillPolygon(brush, somePoints);
    }
}

The finished article: alt text

TreeUK
This does not allow you to see the original image as stated as a requirement in the comments to my answer.
Hogan
This draws the original image with a black box at a given location, I'm not sure what is meant by seeing "the box and the original image" the box doesn't fully obscure the image, is he after a semi-transparent black box?
TreeUK
TreeUK, for each of my points i have an X and a Y access, how does C# accept those points, i can only find using 4 points, i got this: 1,1 | 20,25 | 35,50 | 90,100 and thats gives an x/y point for each cornor (obviously delimit each point with |
Mike
this doesnt compile at using (Graphics g = Graphics.FromImage(pbTest.Image)) -> Error 1 'System.Drawing.Image' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'System.Drawing.Image'
Mike
pbTest in my sample is the name of your PictureBox control.
TreeUK
I've updated the sample to show how you pass the points in.
TreeUK
k it compiles now, just throws this error A Graphics object cannot be created from an image that has an indexed pixel format.
Mike
It looks like that can happen for some gif types, try the solutions mentioned here http://forums.asp.net/p/1195630/2065681.aspx and don't forget to vote me up :)
TreeUK
yeah that link didnt work
Mike