/// <summary> /// Set Up the Bitmap Object and Initialize local members to default values. The Default will make the View include the entire image. /// </summary> /// <param name="OriginalBitmap">Original Bitmap to be viewed.</param> /// <param name="ViewSize">The Size of the control that will view the entire Original Map.</param> public ImageView(Bitmap OriginalBitmap, Size ViewSize) { originalBitmap = OriginalBitmap; relCoverage = FullCoverage; relLocation = UpperLeft; //Aspect Ratios OriginalAspectRatio = originalBitmap.Width / originalBitmap.Height; ViewAspectRatio = ViewSize.Width / ViewSize.Height; this.ViewSize = ViewSize; }
protected virtual void OnViewChanged() { RectangleF NewImage; RectangleF destRect; GraphicsUnit gUnit = GraphicsUnit.Pixel; ViewBitmap = new Bitmap(ViewSize.Width, ViewSize.Height); //if intermediatebm is zoomed all the way in, then don't Graphics g = Graphics.FromImage(ViewBitmap); g.Clear(Color.Black); NewImage = new RectangleF(relLocation * IntermediateSize, relCoverage * IntermediateSize); destRect = new RectangleF((ViewBitmap.Width - NewImage.Width) / 2f, (ViewBitmap.Height - NewImage.Height) / 2f, NewImage.Width, NewImage.Height); if ((IntermediateSize.Height < ViewSize.Height)) //Black Horizontal Bars { Blackorientation = BlackOrientation.Horizontal; relLocation = new RelativePoint(relLocation.X, 0); relCoverage = new RelativeSize(relCoverage.Width, 1); FirstBlack = new SizeF(IntermediateSize.Width, (ViewSize.Height - IntermediateSize.Height) / 2); SecondBlack = new SizeF(IntermediateSize.Width, (ViewSize.Height - IntermediateSize.Height) / 2); g.DrawImage(intermediateBitmap, destRect, NewImage, gUnit); } else if ((IntermediateSize.Width < ViewSize.Width)) //Black Veritcal Bars { Blackorientation = BlackOrientation.Vertical; relLocation = new RelativePoint(0, relLocation.Y); relCoverage = new RelativeSize(1, relCoverage.Height); FirstBlack = new SizeF((ViewSize.Width - IntermediateSize.Width) / 2, IntermediateSize.Height); SecondBlack = new SizeF((ViewSize.Width - IntermediateSize.Width) / 2, IntermediateSize.Height); g.DrawImage(intermediateBitmap, destRect, NewImage, gUnit); } else //No Bars { Blackorientation = null; g.DrawImage(intermediateBitmap, ViewBitmap.GetBounds(ref gUnit), NewImage, GraphicsUnit.Pixel); } if (ViewChanged != null) ViewChanged(this, new EventArgs()); }
public static RelativePoint Min(RelativePoint arg1, RelativePoint arg2) { return new RelativePoint(Math.Min(arg1.X, arg2.X), Math.Min(arg1.Y, arg2.Y)); }