private static Point BottomRightCorner(FlatImage image) { var bottomRightCornerFragments = new[] { new FlatImage(OctaneRenderWindow.LowerRightCorner1), new FlatImage(OctaneRenderWindow.LowerRightCorner2), }; var bottomRightCornerX = 0; var bottomRightCornerY = 0; foreach (var bottomRightCornerFragment in bottomRightCornerFragments) { for (var x = image.Width - bottomRightCornerFragment.Width - 1; x > 0; x--) { for (var y = 0; y < image.Height - bottomRightCornerFragment.Height; y++) { if (image.CompareWithFragmentWithTolerance(bottomRightCornerFragment, x, y)) { bottomRightCornerX = x; bottomRightCornerY = y; return(new Point(bottomRightCornerX, bottomRightCornerY)); } } } } return(new Point(0, 0)); }
private static Point TopLeftCorner(FlatImage image) { var topLeftCornerFragments = new[] { new FlatImage(OctaneRenderWindow.UpperLeftCorner1), new FlatImage(OctaneRenderWindow.UpperLeftCorner2), new FlatImage(OctaneRenderWindow.UpperLeftCorner3), }; var topLeftCornerX = 0; var topLeftCornerY = 0; foreach (var topLeftCornerFragment in topLeftCornerFragments) { for (var x = 0; x < image.Width - topLeftCornerFragment.Width; x++) { for (var y = 0; y < image.Height - topLeftCornerFragment.Height; y++) { if (image.CompareWithFragmentWithTolerance(topLeftCornerFragment, x, y)) { topLeftCornerX = x + topLeftCornerFragment.Width - 1; topLeftCornerY = y + topLeftCornerFragment.Height - 1; return(new Point(topLeftCornerX, topLeftCornerY)); } } } } return(new Point(0, 0)); }
public Rectangle PhotoCanvasRect() { bool found = false; IntPtr inner = IntPtr.Zero; WinApiInterop.NativeMethods.TraverseWindowTree(base.hWnd, PhotoViewerWindow.PhotoCanvasClassName, ref found, ref inner); if (found) { // Canvas var windowRectangle = new WinApiInterop.RECT(); WinApiInterop.NativeMethods.GetWindowRect(inner, ref windowRectangle); var image = WinApiInterop.NativeMethods.GetWindowImage(inner, 0, 0, (windowRectangle.Right - windowRectangle.Left), (windowRectangle.Bottom - windowRectangle.Top)); var flatImage = new FlatImage(image); var borders = PhotoViewerWindow.ImageBorders(flatImage); return(new Rectangle { X = windowRectangle.Left + borders.Left, Y = windowRectangle.Top + borders.Top, Width = borders.Width, Height = borders.Height, }); } else { return(Rectangle.Empty); } }
/// <summary> /// Search image top left point /// </summary> /// <param name="image"></param> /// <param name="topLeftCorner"></param> /// <param name="bottomRightCorner"></param> /// <returns></returns> private static Point TopLeftImage(FlatImage image, Point topLeftCorner, Point bottomRightCorner) { var topLeftImageX = 0; var topLeftImageY = 0; var canvasColor = image.pixels[(int)topLeftCorner.X, (int)topLeftCorner.Y]; for (var y = (int)topLeftCorner.Y; y < (int)bottomRightCorner.Y; y++) { for (var x = (int)topLeftCorner.X; x < (int)bottomRightCorner.X; x++) { if (image.pixels[x, y] != canvasColor) { if (y > (int)topLeftCorner.Y) { topLeftImageX = x; topLeftImageY = y; return(new Point(topLeftImageX, topLeftImageY)); } break; } } } return(new Point(0, 0)); }
public ActionResult DeleteConfirmed(int id) { FlatImage flatImage = db.FlatImages.Find(id); db.FlatImages.Remove(flatImage); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,FlatId")] FlatImage flatImage) { if (ModelState.IsValid) { db.Entry(flatImage).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FlatId = new SelectList(db.Flats, "Id", "Name", flatImage.FlatId); return(View(flatImage)); }
public void GetDerivativeTest() { var flatImage = LoadFlatImageFromResource("ScreenGrid.Tests.Resources.ImageSimple.png"); var stripeMiddle = flatImage.GetHorizontalStripe(flatImage.Height / 2); var dMiddle = FlatImage.GetDerivative(stripeMiddle); Assert.AreEqual(stripeMiddle.Length, dMiddle.Length); // Border detection Assert.AreEqual(0, dMiddle[11]); Assert.Greater(dMiddle[12], 0); }
// GET: FlatImage/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FlatImage flatImage = db.FlatImages.Find(id); if (flatImage == null) { return(HttpNotFound()); } return(View(flatImage)); }
public ActionResult Create(FlatImage flatImage, HttpPostedFileBase Image) { flatImage.Name = System.IO.Path.GetFileName(Image.FileName); if (ModelState.IsValid) { db.FlatImages.Add(flatImage); db.SaveChanges(); Image.SaveAs(Server.MapPath("../Upload/FlatImage/" + flatImage.Id.ToString() + "_" + Image.FileName)); return(RedirectToAction("Index")); } ViewBag.FlatId = new SelectList(db.Flats, "Id", "Name", flatImage.FlatId); return(View(flatImage)); }
// GET: FlatImage/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FlatImage flatImage = db.FlatImages.Find(id); if (flatImage == null) { return(HttpNotFound()); } ViewBag.FlatId = new SelectList(db.Flats, "Id", "Name", flatImage.FlatId); return(View(flatImage)); }
public void FindBordersTest() { var flatImage = LoadFlatImageFromResource("ScreenGrid.Tests.Resources.ImageSimple.png"); const int minimalSegmentLength = 8; var step = flatImage.Height / 8; var list = new List <Tuple <int, int> >(); for (var iy = minimalSegmentLength + step; iy < flatImage.Height - (minimalSegmentLength + step); iy += step) { var stripe = flatImage.GetHorizontalStripe(iy); var derivative = FlatImage.GetDerivative(stripe); var segments = IntegerSegmentUtils.FindZeroSegments(derivative, minimalSegmentLength); Assert.AreEqual(2, segments.Count, String.Format("iy={0}", iy)); } }
public ActionResult DeleteConfirmed(int id) { Flat flat = db.Flats.Find(id); List <FlatImage> fImageList = db.FlatImages.Where(i => i.FlatId == id).ToList(); if (fImageList.Count() > 0) { foreach (var img in fImageList) { FlatImage pimag = new FlatImage(); pimag = img; db.FlatImages.Remove(pimag); db.SaveChanges(); } } db.Flats.Remove(flat); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Search image bottom right point /// </summary> /// <param name="image"></param> /// <param name="topLeftCorner"></param> /// <param name="bottomRightCorner"></param> /// <returns></returns> private static Point BottomRightImage(FlatImage image, Point topLeftCorner, Point bottomRightCorner) { var areaColor2 = image.pixels[(int)bottomRightCorner.X, (int)bottomRightCorner.Y]; for (var y = (int)bottomRightCorner.Y - 1; y > (int)topLeftCorner.Y; y--) { for (var x = (int)bottomRightCorner.X - 1; x > (int)topLeftCorner.X; x--) { if (image.pixels[x, y] != areaColor2) { if (y < bottomRightCorner.Y) { return(new Point(x, y)); } break; } } } return(new Point(0, 0)); }
public static Geometry.Rectangle FindRenderedImageBorders(FlatImage flatImage) { var topLeftCorner = OctaneRenderWindow.TopLeftCorner(flatImage); var bottomRightCorner = OctaneRenderWindow.BottomRightCorner(flatImage); var topLeftImage = OctaneRenderWindow.TopLeftImage(flatImage, topLeftCorner, bottomRightCorner); var bottomRightImage = OctaneRenderWindow.BottomRightImage(flatImage, topLeftCorner, bottomRightCorner); // TODO: && topLeftImageFound && bottomRightImageFound) if ((topLeftCorner.X > 0) && (topLeftCorner.Y > 0) && (bottomRightCorner.X > 0) && (bottomRightCorner.Y > 0) && (topLeftImage.X > 0)) { return(new Geometry.Rectangle { X = topLeftImage.X, Y = topLeftImage.Y, Width = bottomRightImage.X - topLeftImage.X + 1, Height = bottomRightImage.Y - topLeftImage.Y + 1, }); } else { return(Geometry.Rectangle.Empty); } }
private static FlatImage LoadFlatImageFromResource(string resourceName) { FlatImage flatImage; var imageData = ReadResource(resourceName); using (var ms = new System.IO.MemoryStream(imageData)) { using (var original = new Bitmap(ms)) { using (var bitmap = new Bitmap(original.Width, original.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) { using (var g = Graphics.FromImage(bitmap)) { g.DrawImage(original, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); } flatImage = new FlatImage(bitmap); } } } return(flatImage); }
public ActionResult Create(Flat flat, HttpPostedFileBase Image) { var img = System.IO.Path.GetFileName(Image.FileName); if (ModelState.IsValid) { db.Flats.Add(flat); db.SaveChanges(); FlatImage fImage = new FlatImage(); fImage.FlatId = flat.Id; fImage.Name = img; db.FlatImages.Add(fImage); db.SaveChanges(); Image.SaveAs(Server.MapPath("../Upload/FlatImage/" + fImage.Id.ToString() + "_" + img)); return(RedirectToAction("Index")); } ViewBag.DiscountId = new SelectList(db.Discounts, "Id", "Name", flat.DiscountId); ViewBag.FlatTypeId = new SelectList(db.FlatTypes, "Id", "Name", flat.FlatTypeId); ViewBag.PropertyId = new SelectList(db.Properties, "Id", "Name", flat.PropertyId); return(View(flat)); }
private static Rectangle ImageBorders(FlatImage image) { var whiteColor = BitConverter.ToUInt32(new byte[] { 0, 255, 255, 255 }, 0); int?top = null; for (var iy = 0; iy < image.Height; iy++) { for (var ix = 0; ix < image.Width; ix++) { if (image.pixels[ix, iy] != whiteColor) { top = iy; break; } } if (top.HasValue) { break; } } int?bottom = null; for (var iy = image.Height - 1; iy >= 0; iy--) { for (var ix = 0; ix < image.Width; ix++) { if (image.pixels[ix, iy] != whiteColor) { bottom = iy; break; } } if (bottom.HasValue) { break; } } int?left = null; for (var ix = 0; ix < image.Width; ix++) { for (var iy = 0; iy < image.Height; iy++) { if (image.pixels[ix, iy] != whiteColor) { left = ix; break; } } if (left.HasValue) { break; } } int?right = null; for (var ix = image.Width - 1; ix >= 0; ix--) { for (var iy = 0; iy < image.Height; iy++) { if (image.pixels[ix, iy] != whiteColor) { right = ix; break; } } if (right.HasValue) { break; } } return(new Rectangle { X = left.Value, Y = top.Value, Width = right.Value - left.Value + 1, Height = bottom.Value - top.Value + 1, }); }