Dynamically Positioning the Control (JavaScript)

Take the following steps to dynamically scale and position the LEAD RasterView control when loading an image. This example scales the control to use most of the browser’s area while preserving the image's aspect ratio.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

Delete the <FORM> </FORM> tags and what’s between them and the LoadImage subroutine, and replace the code in the Window_OnLoad() function with the following code:

var HeightFactor; 
var WidthFactor; 
var HeightAllowed; 
var WidthAllowed; 
var NewWidth; 
var NewHeight; 

//Modify the browser windows’s size and position so that it takes up most of the screen. 
NewHeight = screen.height * 0.8; 
NewWidth = screen.width * 0.9; 
window.resizeTo(NewWidth, NewHeight); 
window.moveTo((screen.Width - NewWidth) / 2, (screen.Height - NewHeight) / 2); 
LEADRasterView1.ScaleMode = 3; 

//Turn off automated behavior while we load and manipulate the image. 
LEADRasterView1.AutoRepaint = false; 
LEADRasterView1.AutoScroll = false; 
LEADRasterView1.BackErase = false; 

//Load the bitmap. This hard-coded path name may be different on your system. 
RasterIO1.Load(LEADRasterView1.Raster, "i:\\a\\pic\\20010327047.jpg", 0, 0, 1); 
//Set the variables used for preserving the aspect ratio. 
//The units of measure do not matter, since we are calculating proportions. 
HeightFactor = LEADRasterView1.RasterUnk.BitmapHeight
WidthFactor = LEADRasterView1.RasterUnk.BitmapWidth
HeightAllowed = NewHeight * 3 / 4; 
WidthAllowed = NewWidth * 3 / 4; 
//Check to see if using the maximum width will make the image too tall. Set the dimensions based on the result. 
if (((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed) 
{
   LEADRasterView1.Width = WidthAllowed; 
   LEADRasterView1.Height = (LEADRasterView1.Width * HeightFactor) / WidthFactor; 
}
else
{
   LEADRasterView1.Height = HeightAllowed; 
   LEADRasterView1.Width = (LEADRasterView1.Height * WidthFactor) / HeightFactor; 
}
//Set the image display size to match the LEAD control
var PAINTSIZEMODE_FIT = 3; 
LEADRasterView1.PaintSizeMode = PAINTSIZEMODE_FIT;
//Turn on automated behavior while we load and manipulate the image. 
LEADRasterView1.AutoRepaint = true; 

3.

Run your page to test it.