2005-07-06, 09:09 PM
You need to maintain the centre of the image as your referenced coordinates.
SUBROUINE
void MyDrawImage(int CentreX, int CentreY, int Width, int Height )
{
int W = Width / 2;
int H = Height / 2;
// Set SourceImage to be the rectangle coordinates in the image file
System.Drawing.Rectangle SourceImage = new System.Drawing.Rectangle(CentreX - W, CentreY - H , Width, Height)
// Set DestImage to be the rectangle coordinates on the screen where the image is to be placed
System.Drawing.Rectangle DestImage = new System.Drawing.Rectangle(60,60,500,500) // put your numbers here
Graphics.FromImage(backgroundImage).DrawImage(TheJPEGAsAnImage, DestImage , SourceImage , GraphicsUnit.Pixel,imageAttr);
}
MAIN ROUTINE
// Initialisation
// I Assume That TheImageWidth and TheImageHeight are declared to be the source jpeg image width and height respectivelly
int CentreX, CentreY, Width, Height;
double Zoom = 1.0;
CentreX = TheImageWidth / 2;
CentreY = TheImageHeight / 2;
// Zoom in
Zoom = Zoom * 2.0;
if ( Zoom >= 64.0 ) then Zoom = 64.0; // just to bound the value
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Zoom out
Zoom = Zoom / 2.0;
if ( Zoom < 1.0 ) then Zoom = 1.0; // just to bound the value
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan left
CentreX = CentreX - 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Right
CentreX = CentreX + 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Up
CentreY = CentreY - 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Down
CentreY = CentreY + 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
The only thing I haven't included is if the image is zoomed in, panned across one direction and then the user zooms out you will have to update CentreX and/or CentreY to reposition the image location.
SUBROUINE
void MyDrawImage(int CentreX, int CentreY, int Width, int Height )
{
int W = Width / 2;
int H = Height / 2;
// Set SourceImage to be the rectangle coordinates in the image file
System.Drawing.Rectangle SourceImage = new System.Drawing.Rectangle(CentreX - W, CentreY - H , Width, Height)
// Set DestImage to be the rectangle coordinates on the screen where the image is to be placed
System.Drawing.Rectangle DestImage = new System.Drawing.Rectangle(60,60,500,500) // put your numbers here
Graphics.FromImage(backgroundImage).DrawImage(TheJPEGAsAnImage, DestImage , SourceImage , GraphicsUnit.Pixel,imageAttr);
}
MAIN ROUTINE
// Initialisation
// I Assume That TheImageWidth and TheImageHeight are declared to be the source jpeg image width and height respectivelly
int CentreX, CentreY, Width, Height;
double Zoom = 1.0;
CentreX = TheImageWidth / 2;
CentreY = TheImageHeight / 2;
// Zoom in
Zoom = Zoom * 2.0;
if ( Zoom >= 64.0 ) then Zoom = 64.0; // just to bound the value
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Zoom out
Zoom = Zoom / 2.0;
if ( Zoom < 1.0 ) then Zoom = 1.0; // just to bound the value
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan left
CentreX = CentreX - 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Right
CentreX = CentreX + 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Up
CentreY = CentreY - 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
// Pan Down
CentreY = CentreY + 10 // 10 is my pan value, use yours
Width = TheImageWidth / Zoom;
Height = TheImageHeight / Zoom;
MyDrawImage ( CentreX, CentreY, Width, Height);
The only thing I haven't included is if the image is zoomed in, panned across one direction and then the user zooms out you will have to update CentreX and/or CentreY to reposition the image location.