public void RotateImageTest() { string imagePath = CommonTest.GetFileResourcePath("poneis_malditos.jpg"); ImageUtils target = new ImageUtils(); Image b = Image.FromFile(imagePath); float angle = 90F; Image actual; actual = target.RotateImage(b, angle); //Verify if dimensions were rotated Assert.AreEqual(b.Height, actual.Width); Assert.AreEqual(b.Width, actual.Height); }
public ImageZoomMainForm(String imagePath) { InitializeComponent(); this.WindowState = FormWindowState.Maximized; imageState = new ImageState(); imageState.Zoom = 1f; imageState.X = 0; imageState.Y = 0; imageState.Angle = 0; string imagefilename = imagePath; loadImage(imagefilename); imageState.Width = img.Width; imageState.Height = img.Height; pictureBox.Paint += new PaintEventHandler(imageBox_Paint); this.Show(); this.WindowState = FormWindowState.Maximized; this.Activate(); imageUtils = new ImageUtils(); imageUtils.Center = getCenterPoint(); imageUtils.BoxSize = pictureBox.Size; imageUtils.ImageSize = img.Size; Graphics g = this.CreateGraphics(); setViewMinimumBounds(0,0,img.Width, img.Height, img.Height, img.Width, 0); interceptor = new InterceptKeyboard(); InterceptKeyboard.SetHook(interceptor.hook); interceptor.KeyEvent += keyDown; zoomLabel.Text = "zoom is: " + imageState.Zoom; }
public void imageShouldBeShownAllIfFitsAndNoShift() { ImageUtils target = new ImageUtils(); int left = 0; int top = 0; int right = 100; int bottom = 100; float otherImageScaleH = 1; float otherImageScaleW = 1; ImageState actual; ImageState expected = new ImageState(); expected.X = 0; expected.Y = 0; expected.Zoom = 1f; target.ImageSize = new Size(100,100); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }
public void imageSizeMultipliersShouldCompareCorrectDimensions() { ImageUtils target = new ImageUtils(); Size imageSize = new Size(200, 100); Size otherImageSize = new Size(200, 100); float[] multipliers = target.MultipliersToSameSize(imageSize, otherImageSize, 0); Assert.AreEqual(1, multipliers[0]); Assert.AreEqual(1, multipliers[1]); }
public void imageSizeMultipliersShouldBeTwiceIfOtherImageIsTwiceTheSize() { ImageUtils target = new ImageUtils(); Size imageSize = new Size(200,100); Size otherImageSize = new Size(400,200); float[] multipliers = target.MultipliersToSameSize(imageSize, otherImageSize,0); Assert.AreEqual(2, multipliers[0]); Assert.AreEqual(2, multipliers[1]); }
public void imageSizeComesRotated90DegreesAsIndicatedMultipliersShouldCompareCorrectDimensions() { ImageUtils target = new ImageUtils(); Size imageSize = new Size(200, 100); //width, height zero degrees Size otherImageSize = new Size(200, 100); //width,height 90 degrees, turn as height, width, zero degrees float[] multipliers = target.MultipliersToSameSize(imageSize, otherImageSize, 90); Assert.AreEqual(2, multipliers[0]); Assert.AreEqual(0.5f, multipliers[1]); }
public void imageHeightMultiplierShouldBeHalfIfHeightTwiceTheHalfImage() { ImageUtils target = new ImageUtils(); float expectedMultiplier = 0.5f; float actualMultiplier = target.MultiplierToSameHeight(100, 50); Assert.AreEqual(expectedMultiplier, actualMultiplier); }
public void imageHeightMultiplierShouldBeTwoIfHeightIsTwiceTheOriginalImage() { ImageUtils target = new ImageUtils(); float expectedMultiplier = 2; float actualMultiplier = target.MultiplierToSameWidth(100, 200); Assert.AreEqual(expectedMultiplier, actualMultiplier); }
public void imageShouldBeZommedWithSamePositioningWhenRotated90AndIsNotSquared() { ImageUtils target = new ImageUtils(); int left = 50; int top = 50; int right = 75; int bottom = 75; float otherImageScaleH = 1; float otherImageScaleW = 1; ImageState actual; ImageState expected = new ImageState(); expected.X = -left; expected.Y = -top; expected.Zoom = 4f; expected.Angle = 90; target.ImageSize = new Size(200, 100); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW, 90); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }
public void imageShouldBeShiftedToTwiceBottomWhenScaledRightIsDoubled() { ImageUtils target = new ImageUtils(); int left = 0; int top = 100; int right = 200; int bottom = 300; float otherImageScaleH = 2f; float otherImageScaleW = 2f; ImageState actual; ImageState expected = new ImageState(); expected.X = 0; expected.Y = -50; expected.Zoom = 1f; expected.Angle = 0; target.ImageSize = new Size(100, 200); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }
public void imageShouldBeShiftedToBottomAsRequestedAndCantFitAllWhenRotated90() { ImageUtils target = new ImageUtils(); int left = 0; int top = 100; int right = 100; int bottom = 200; float otherImageScaleH = 1; float otherImageScaleW = 1; ImageState actual; ImageState expected = new ImageState(); expected.X = 0; expected.Y = -top; expected.Zoom = 1f; expected.Angle = 90; target.ImageSize = new Size(100, 1000); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW, 90); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }
public void imageShouldBeShiftedRightSameWayWhenIsRotated180() { ImageUtils target = new ImageUtils(); int left = 100; int top = 0; int right = 200; int bottom = 100; float otherImageScaleH = 1; float otherImageScaleW = 1; ImageState actual; ImageState expected = new ImageState(); expected.X = -left; expected.Y = 0; expected.Zoom = 1f; expected.Angle = 180; target.ImageSize = new Size(1000, 100); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW, 180); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }
public void imageShouldBeZommedIfDesiredPartCanBeShownBigger() { ImageUtils target = new ImageUtils(); int left = 50; int top = 50; int right = 75; int bottom = 75; float otherImageScaleH = 1; float otherImageScaleW = 1; ImageState actual; ImageState expected = new ImageState(); expected.X = -left; expected.Y = -top; expected.Zoom = 4f; target.ImageSize = new Size(100, 100); target.BoxSize = new Size(100, 100); actual = target.AdjustPositionAndScale(left, top, right, bottom, otherImageScaleH, otherImageScaleW); Assert.AreEqual(expected.X, actual.X); Assert.AreEqual(expected.Y, actual.Y); Assert.AreEqual(expected.Zoom, actual.Zoom); Assert.AreEqual(expected.Angle, actual.Angle); }