// generalized method to paste clip without scaling in one of 4 corners of picture private void pasteClip(Course.ImagePlacement place) { working(true); saveText(); course.Paste(place); saveCourse(); updateScreen(); working(false); }
// Method to set the image bitmap depending on placement option public void SetImage(Bitmap image, Course.ImagePlacement place) { switch (place) { case Course.ImagePlacement.fit: saveImage(resizeImage(image, imageWidth, imageHeight)); break; default: saveImage(clipImage(image, imageWidth, imageHeight, place)); break; } }
// Method to clip the image without resizing, depending on which corner it is aligned to. private Bitmap clipImage(Bitmap bm, int w, int h, Course.ImagePlacement place) { Bitmap result = new Bitmap(w, h); // first rotate / flip depending on ultimate placement switch (place) { case Course.ImagePlacement.lowerLeft: bm.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case Course.ImagePlacement.lowerRight: bm.RotateFlip(RotateFlipType.RotateNoneFlipXY); break; case Course.ImagePlacement.upperRight: bm.RotateFlip(RotateFlipType.RotateNoneFlipX); break; } // unscaled clip, always to upper left corner using (Graphics g = Graphics.FromImage((System.Drawing.Image)result)) g.DrawImageUnscaled(bm, 0, 0, w, h); bm.Dispose(); // do the inverse of the rotate / flip switch (place) { case Course.ImagePlacement.lowerLeft: result.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case Course.ImagePlacement.lowerRight: result.RotateFlip(RotateFlipType.RotateNoneFlipXY); break; case Course.ImagePlacement.upperRight: result.RotateFlip(RotateFlipType.RotateNoneFlipX); break; } return(result); }