Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying from one image to another (issue with dimensions)

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm working on a form which makes use of Bitmap / Graphics objects which I am drawing rectangles onto.
I have to specify a starting size (dimensions) of the Bitmap before I start drawing onto it.
HOWEVER in practise I do not know the resultant size that I need the Bitmap to be until after completion of my processes and establishing dimensions / whereabouts of the rectangles being drawn.
This can result in my intended Bitmap being too small to draw on with some rectangles not seen (as drawn off the edges).
My thoughts on this were to make use of a second Bitmap (after I've established the size as required) and then copy from the first onto the second (with the correct size) in the hope of retrieving the lost graphics.
I've tried doing this as follows :

Bitmap bmp2 = new Bitmap(bmp1, new Size(200, 200));

As my original bitmap is 100x100 the result is that my image appears twice the size.

How can I achieve what I'm trying to do ?
That is, draw onto a bitmap, and then having worked out its dimensions (as determined through processing / drawing of rectangles) create a second and copy the graphics to that - retrieving the lost drawings.

Any help would be appreciated.
Steve
 
Bitmap bmp2 = new Bitmap(200, 200);
for(int x=0; x<100; x++){
for(int y=0; y<100; y++){
bmp2.setPixel(x, y, bmp1.getPixel(x, y));
}
}

- it's slow, but it'll get you there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top