public void EndCropImage(Point endPoint) { var r = BitmapUtility.GetRect(StartPoint, endPoint); if (r.Width < 10 || r.Height < 10) { return; } var bmp = BitmapUtility.TakeScreenshotOfSpecificRect(StartPoint, endPoint); CreateNewAsset(bmp); ImageCropped?.Invoke(bmp); ImageCropEnded?.Invoke(endPoint); IsCropping = false; StartPoint = Point.Empty; }
private Rectangle DrawFoundImageUnderCursor(Graphics g) { var bmp = (m_AssetUnderCursor != null) ? m_AssetUnderCursor.Importer.Load <Bitmap>() : Resources.X_ICO_256; var ratio = k_MaxImagePreviewSize * 1.0f / (bmp.Width > bmp.Height ? bmp.Width : bmp.Height); ratio *= (m_AssetUnderCursor != null) ? 1 : 0.4f; var rect = new Rectangle(m_LastCursorPos, new Size((int)(bmp.Width * ratio), (int)(bmp.Height * ratio))); var opacity = GetOpacityValue((int)m_FindImageWatch.ElapsedMilliseconds, k_ImageShowLength); if (m_LastScreeBmpAtPos == null) { m_LastScreeBmpAtPos = BitmapUtility.TakeScreenshotOfSpecificRect(rect.Location, rect.Size); } var bmp2 = BitmapUtility.ResizeBitmap(bmp, rect); var bmp3 = BlendTwoImagesWithOpacity(m_LastScreeBmpAtPos, bmp2, opacity); g.DrawImage(bmp3, rect); return(rect); }
private Asset FindImage(Point cursorPos) { Profiler.Start("RecordingManager_FindImage"); Profiler.Start("RecordingManager_CropFromScreen"); var size = k_ImageForReferenceSearchUnderCursorSize; var crop = BitmapUtility.TakeScreenshotOfSpecificRect( WinAPI.GetCursorPosition().Sub(new Point(size.Width / 2, size.Width / 2)), size); Profiler.Stop("RecordingManager_CropFromScreen"); Profiler.Start("RecordingManager_FindAssetReference"); // TODO: FeatureDetector.Get will fail to find proper match if another thread already used/is using it var detector = FeatureDetectorFactory.Create(DetectorNamesHardcoded.PixelPerfect); Asset retAsset = null; foreach (var asset in AssetManager.Assets) { if (asset.HoldsTypeOf(typeof(Bitmap))) { if (detector.FindImagePos(crop, asset.Importer.Load <Bitmap>()) != null) { ImageFoundInAssets?.Invoke(asset, cursorPos); retAsset = asset; break; } } } Profiler.Stop("RecordingManager_FindAssetReference"); Profiler.Stop("RecordingManager_FindImage"); if (retAsset == null) { ImageNotFoundInAssets?.Invoke(cursorPos); } return(retAsset); }