/// <summary> /// Overlays pixel data from another <see cref="BitmapBuffer"/>, with alpha blending. /// </summary> /// <param name="x"> /// The x-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param> /// <param name="y"> /// The y-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param> /// <param name="source"> /// Another <see cref="BitmapBuffer"/> containing the rectangle to overlay.</param> /// <param name="bounds"> /// The pixel rectangle within the specified <paramref name="source"/> to overlay.</param> /// <param name="color"> /// The <see cref="Color"/> to substitute for all <paramref name="source"/> pixels.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="source"/> is a null reference.</exception> /// <remarks><para> /// <b>Overlay</b> blends all <see cref="Pixels"/> elements within the specified <paramref /// name="bounds"/> of the specified <paramref name="source"/> buffer with the corresponding /// <see cref="Pixels"/> elements in this <see cref="BitmapBuffer"/>, starting with the /// specified <paramref name="x"/> and <paramref name="y"/> coordinates. /// </para><para> /// <b>Overlay</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha blending /// between the specified <paramref name="source"/> buffer (acting as the overlay) and this /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is /// performed. /// </para><para> /// <b>Overlay</b> substitutes the specified <paramref name="color"/> for the actual color /// channels of each <paramref name="source"/> pixel, while using its alpha channel to /// govern alpha blending with the corresponding <see cref="Pixels"/> element. The alpha /// channel of the specified <paramref name="color"/> is ignored.</para></remarks> public void Overlay(int x, int y, BitmapBuffer source, RectI bounds, Color color) { if (source == null) { ThrowHelper.ThrowArgumentNullException("source"); } int sourceOffset = bounds.X + source._size.Width * bounds.Y; int targetOffset = x + _size.Width * y; for (int dy = 0; dy < bounds.Height; dy++) { for (int dx = 0; dx < bounds.Width; dx++) { uint p0 = source._pixels[sourceOffset + dx]; uint p1 = _pixels[targetOffset + dx]; // multiply color channels with source alpha color.A = (byte)(p0 >> 24); p0 = BitmapUtility.ColorToPbgra32(color); _pixels[targetOffset + dx] = BitmapUtility.BlendPbgra32(p0, p1); } sourceOffset += source._size.Width; targetOffset += _size.Width; } }
/// <overloads> /// Makes the <see cref="BitmapBuffer"/> fully opaque.</overloads> /// <summary> /// Makes the <see cref="BitmapBuffer"/> fully opaque.</summary> /// <remarks> /// <b>MakeOpaque</b> replaces all <see cref="Pixels"/> elements with their <see /// cref="BitmapUtility.OpaquePbgra32"/> equivalents. Fully transparent pixels remain /// unchanged.</remarks> public void MakeOpaque() { for (int i = 0; i < _pixels.Length; i++) { _pixels[i] = BitmapUtility.OpaquePbgra32(_pixels[i]); } }
/// <summary> /// دریافت آرایه بایت تصویر برای محصول /// </summary> /// <param name="fileName">نام فایل</param> /// <returns>آرایه بایت شده تصویر</returns> private byte[] GetProductFileByte(string filePath) { Image image = Image.FromFile(Server.MapPath(filePath)); var resizedImage = BitmapUtility.FixedSize(image, 886, 142, true); return(BitmapUtility.ImageToByteArray(resizedImage)); }
public GraphViewModel(IInspectorTool inspectorTool) { DisplayName = "[New Graph]"; _elements = new BindableCollection <ElementViewModel>(); _connections = new BindableCollection <ConnectionViewModel>(); _inspectorTool = inspectorTool; var element1 = AddElement <ImageSource>(100, 50); element1.Bitmap = BitmapUtility.CreateFromBytes(DesignTimeImages.Desert); var element2 = AddElement <ColorInput>(100, 300); element2.Color = Colors.Green; var element3 = AddElement <Add>(400, 250); Connections.Add(new ConnectionViewModel( element1.OutputConnector, element3.InputConnectors[0])); Connections.Add(new ConnectionViewModel( element2.OutputConnector, element3.InputConnectors[1])); element1.IsSelected = true; }
/// <summary> /// Blends the specified pixel in the <see cref="BitmapBuffer"/> with the specified <see /// cref="Color"/>.</summary> /// <param name="x"> /// The x-coordinate of the pixel to blend with <paramref name="color"/>.</param> /// <param name="y"> /// The y-coordinate of the pixel to blend with <paramref name="color"/>.</param> /// <param name="color"> /// The <see cref="Color"/> to blend with the pixel at the specified location in the <see /// cref="BitmapBuffer"/>.</param> /// <remarks><para> /// <b>BlendPixel</b> blends the <see cref="Pixels"/> element at the specified <paramref /// name="x"/> and <paramref name="y"/> coordinates with the <see /// cref="PixelFormats.Pbgra32"/> representation of the specified <paramref name="color"/>. /// </para><para> /// <b>BlendPixel</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha /// blending between the specified <paramref name="color"/> (acting as the overlay) and this /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is /// performed.</para></remarks> public void BlendPixel(int x, int y, Color color) { uint value = BitmapUtility.ColorToPbgra32(color); int i = x + _size.Width * y; _pixels[i] = BitmapUtility.BlendPbgra32(value, _pixels[i]); }
/// <summary> /// دریافت آرایه بایت تصویر برای محصول /// </summary> /// <param name="fileName">نام فایل</param> /// <returns>آرایه بایت شده تصویر</returns> private byte[] GetProductFileByte(string fileName) { var filePath = string.Format("~/upload/product/{0}", fileName); Image image = Image.FromFile(Server.MapPath(filePath)); var resizedImage = BitmapUtility.FixedSize(image, 500, 500, true); return(BitmapUtility.ImageToByteArray(resizedImage)); }
protected override void OnClosed(EventArgs e) { // TODO: refactor - dispose should happen in Dispose event unsafe { BitmapUtility.DisposeBitmap((void *)m_BitmapPtr); BitmapUtility.DisposeCachedBitmap((void *)m_CachedBitmapPtr); } }
/// <summary> /// Clears the <see cref="BitmapBuffer"/> with the specified <see cref="Color"/>.</summary> /// <param name="color"> /// The new <see cref="Color"/> for all pixels in the <see cref="BitmapBuffer"/>.</param> /// <remarks> /// <b>Clear</b> sets all elements of the <see cref="Pixels"/> array to the <see /// cref="PixelFormats.Pbgra32"/> representation of the specified <paramref name="color"/>. /// </remarks> public void Clear(Color color) { uint value = BitmapUtility.ColorToPbgra32(color); for (int i = 0; i < _pixels.Length; i++) { _pixels[i] = value; } }
private void DrawCroppingRectangle(Graphics g) { var rect = BitmapUtility.GetRect(CroppingManager.StartPoint, WinAPI.GetCursorPosition()); rect.Location = rect.Location.Sub(new Point(1, 1)); rect.Width++; rect.Height++; g.DrawRectangle(Pens.Black, rect); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } var image = (BitmapImage)value; return(BitmapUtility.BitmapImage2Bitmap(image)); }
public void ColorToPbgra32() { Assert.AreEqual(0xFF203040, BitmapUtility.ColorToPbgra32( Color.FromArgb(0xFF, 0x20, 0x30, 0x40))); Assert.AreEqual(0x7F0F171F, BitmapUtility.ColorToPbgra32( Color.FromArgb(0x7F, 0x20, 0x30, 0x40))); Assert.AreEqual(0x00000000, BitmapUtility.ColorToPbgra32( Color.FromArgb(0x00, 0x20, 0x30, 0x40))); }
public void ColorFromPbgra32() { Assert.AreEqual(Color.FromArgb(0xFF, 0x20, 0x30, 0x40), BitmapUtility.ColorFromPbgra32(0xFF203040)); Assert.AreEqual(Color.FromArgb(0x7F, 0x1E, 0x2E, 0x3E), BitmapUtility.ColorFromPbgra32(0x7F0F171F)); Assert.AreEqual(Color.FromArgb(0x00, 0x00, 0x00, 0x00), BitmapUtility.ColorFromPbgra32(0x00000000)); }
/*-------------------------------------------------------------------------------------------------------*/ private void BtnSave_Click(object sender, RoutedEventArgs e) { var dialog = new SaveFileDialog { Filter = "Bitmap Image|*.bmp" }; if (dialog.ShowDialog() == true) { BitmapUtility.SaveImage(_SnapShotBMP, dialog.FileName); } }
public TestUtility( TestConfiguration config, BitmapUtility bitmapUtility, BitmapConverter bitmapConverter, BitmapBlender bitmapBlender) { Config = config; BitmapUtility = bitmapUtility; BitmapConverter = bitmapConverter; BitmapBlender = bitmapBlender; }
/// <summary> /// Makes the specified <see cref="Color"/> transparent in the <see cref="BitmapBuffer"/>. /// </summary> /// <param name="color"> /// The <see cref="Color"/> to replace with transparent black.</param> /// <remarks><para> /// <b>MakeTransparent</b> sets all fully opaque <see cref="Pixels"/> of the specified /// <paramref name="color"/> to zero, which is the <see cref="PixelFormats.Pbgra32"/> /// equivalent of transparent black color. Partially transparent <see cref="Pixels"/> and /// <see cref="Pixels"/> of any other color remain unchanged. /// </para><para> /// <b>MakeTransparent</b> ignores the alpha channel of the specified <paramref /// name="color"/> and only replaces fully opaque <see cref="Pixels"/> because the /// imprecision caused by the premultiplication of color channels in the <see /// cref="PixelFormats.Pbgra32"/> format would otherwise produce false matches. /// </para><note type="implementnotes"> /// The predefined <see cref="Colors.Transparent"/> color is transparent <em>white</em> (all /// color channels maximized), not transparent <em>black</em> (all color channels zero). /// That color is not representable in <see cref="PixelFormats.Pbgra32"/> format since all /// color channel information of fully transparent color is lost.</note></remarks> public void MakeTransparent(Color color) { uint value = BitmapUtility.ColorToOpaquePbgra32(color); for (int i = 0; i < _pixels.Length; i++) { if (_pixels[i] == value) { _pixels[i] = 0u; } } }
public MainForm() { InitializeComponent(); Bitmap bitmap; using (var stream = typeof(MainForm).Assembly.GetManifestResourceStream("FormApplication.character.png")) { bitmap = (Bitmap)Bitmap.FromStream(stream); } unsafe { m_BitmapPtr = (IntPtr)BitmapUtility.GetBitmapPtrFromHICON((void *)bitmap.GetHicon()); } }
private void OnUpdate() { if (m_ObservedScreen != null) { lock (ScreenStateThread.ScreenBmpLock) lock (m_ObservedScreenLock) { BitmapUtility.Clone32BPPBitmap(ScreenStateThread.ScreenBmp, m_ObservedScreen); } } Invalidate?.Invoke(); }
public void StartNewImageSearch(Bitmap sampleImage) { lock (m_SampleImageLock) { var clonedSampleImage = new Bitmap(sampleImage.Width, sampleImage.Height); m_SampleImage = BitmapUtility.Clone32BPPBitmap(sampleImage, clonedSampleImage); WasLastCheckSuccess = false; WasImageFound = false; LastKnownPositions = null; TimeSinceLastFind = 0; m_Watch.Restart(); } }
protected override void ThreadAction() { Profiler.Start(Name); Profiler.Start(Name + "_TakeScreenshot"); BitmapUtility.TakeScreenshot(m_TempBitmap); Profiler.Stop(Name + "_TakeScreenshot"); Profiler.Start(Name + "_CloneBitmap"); lock (ScreenBmpLock) { BitmapUtility.Clone32BPPBitmap(m_TempBitmap, ScreenBmp); } Profiler.Stop(Name + "_CloneBitmap"); Profiler.Stop(Name); }
/// <summary> /// Clears the specified rectangle in the <see cref="BitmapBuffer"/> with the specified <see /// cref="Color"/>.</summary> /// <param name="bounds"> /// The pixel rectangle in the <see cref="BitmapBuffer"/> to fill with the specified /// <paramref name="color"/>.</param> /// <param name="color"> /// The new <see cref="Color"/> for all pixels within the specified <paramref /// name="bounds"/> of the <see cref="BitmapBuffer"/>.</param> /// <remarks> /// <b>Clear</b> sets all <see cref="Pixels"/> elements within the specified <paramref /// name="bounds"/> to the <see cref="PixelFormats.Pbgra32"/> representation of the /// specified <paramref name="color"/>. No coordinate checking is performed.</remarks> public void Clear(RectI bounds, Color color) { uint value = BitmapUtility.ColorToPbgra32(color); int offset = bounds.X + _size.Width * bounds.Y; for (int y = 0; y < bounds.Height; y++) { for (int x = 0; x < bounds.Width; x++) { _pixels[offset + x] = value; } offset += _size.Width; } }
/// <summary> /// Makes the specified rectangle in the <see cref="BitmapBuffer"/> fully opaque.</summary> /// <param name="bounds"> /// The pixel rectangle in the <see cref="BitmapBuffer"/> to make opaque.</param> /// <remarks> /// <b>MakeOpaque</b> replaces all <see cref="Pixels"/> elements within the specified /// <paramref name="bounds"/> with their <see cref="BitmapUtility.OpaquePbgra32"/> /// equivalents. Fully transparent pixels remain unchanged. No coordinate checking is /// performed.</remarks> public void MakeOpaque(RectI bounds) { int offset = bounds.X + _size.Width * bounds.Y; for (int y = 0; y < bounds.Height; y++) { for (int x = 0; x < bounds.Width; x++) { int i = offset + x; _pixels[i] = BitmapUtility.OpaquePbgra32(_pixels[i]); } offset += _size.Width; } }
protected override void ThreadAction() { if (ObservedImage == null) { return; } if (m_SampleImage == null) { return; } Profiler.Start(Name); Profiler.Start(Name + "_CloneScreen"); lock (ScreenStateThread.ScreenBmpLock) { BitmapUtility.Clone32BPPBitmap(ScreenStateThread.ScreenBmp, ObservedImage); } Profiler.Stop(Name + "_CloneScreen"); Profiler.Start(Name + "_FindMatch"); var points = FindImagePositions(); var success = ValidatePointsCorrectness(points); Profiler.Stop(Name + "_FindMatch"); if (success) { PositionFound?.Invoke(points); LastKnownPositions = points; WasImageFound = true; WasLastCheckSuccess = true; TimeSinceLastFind = 0; m_Watch.Restart(); } else { WasLastCheckSuccess = false; TimeSinceLastFind = (int)m_Watch.ElapsedMilliseconds; } Profiler.Stop(Name); }
protected override void OnPaint(PaintEventArgs e) { var graphics = e.Graphics; IntPtr hdc; if (m_CachedBitmapPtr == IntPtr.Zero) { hdc = graphics.GetHdc(); unsafe { m_CachedBitmapPtr = (IntPtr)BitmapUtility.CreateCachedBitmapPtr((void *)m_BitmapPtr, (void *)hdc); } graphics.ReleaseHdc(hdc); } hdc = graphics.GetHdc(); unsafe { BitmapUtility.DrawCachedBitmap((void *)hdc, (void *)m_CachedBitmapPtr, 0, 0); } graphics.ReleaseHdc(hdc); }
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 WpfSize ConvertSize(SizeF size, WpfSize availableSize, out WpfSize renderSize) { double ratio; if (Orientation == Orientation.Vertical) { ratio = availableSize.Width / size.Width; } else { ratio = availableSize.Height / size.Height; } if (!double.IsNaN(MaxScale)) { ratio = Math.Min(ratio, MaxScale); } var newSize = new WpfSize((int)(size.Width * ratio), (int)(size.Height * ratio)); renderSize = BitmapUtility.ConvertSize(newSize); return(newSize); }
public void SaveDetected() { var person = new PersonModelBase() { Name = _controls.Name, Age = Convert.ToInt32(_controls.Age), Address = _controls.Address, Details = _controls.Details }; var image = new ImageModelBase() { Data = BitmapUtility.BitmapToByteArray(_controls.TheNewestFace) }; try { if (_parameters.UseExplorer) { _localStorageService.SaveFace(person, image); } else { _databaseService.SaveFace(new PersonModel(person), new ImageModel(image)); } } catch (Exception e) { MessageBox.Show("Wystąpił błąd podczas zapisu do bazy danych\r\n\r\n" + e); } _controls.KnownPeople = _parameters.UseExplorer ? _localStorageService.GetPeopleNames() : _databaseService.GetPeopleNames(); _controls.StatusText = StatusTypes.SaveCompleted.GetDesciption(); _controls.IsNewUpdate = true; StatusBarUtility.ResestStatus(_controls); }
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); }
/// <overloads> /// Overlays pixel data from another <see cref="BitmapBuffer"/>.</overloads> /// <summary> /// Overlays pixel data from another <see cref="BitmapBuffer"/>, with alpha blending. /// </summary> /// <param name="x"> /// The x-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param> /// <param name="y"> /// The y-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param> /// <param name="source"> /// Another <see cref="BitmapBuffer"/> containing the rectangle to overlay.</param> /// <param name="bounds"> /// The pixel rectangle within the specified <paramref name="source"/> to overlay.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="source"/> is a null reference.</exception> /// <remarks><para> /// <b>Overlay</b> blends all <see cref="Pixels"/> elements within the specified <paramref /// name="bounds"/> of the specified <paramref name="source"/> buffer with the corresponding /// <see cref="Pixels"/> elements in this <see cref="BitmapBuffer"/>, starting with the /// specified <paramref name="x"/> and <paramref name="y"/> coordinates. /// </para><para> /// <b>Overlay</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha blending /// between the specified <paramref name="source"/> buffer (acting as the overlay) and this /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is /// performed.</para></remarks> public void Overlay(int x, int y, BitmapBuffer source, RectI bounds) { if (source == null) { ThrowHelper.ThrowArgumentNullException("source"); } int sourceOffset = bounds.X + source._size.Width * bounds.Y; int targetOffset = x + _size.Width * y; for (int dy = 0; dy < bounds.Height; dy++) { for (int dx = 0; dx < bounds.Width; dx++) { uint p0 = source._pixels[sourceOffset + dx]; uint p1 = _pixels[targetOffset + dx]; _pixels[targetOffset + dx] = BitmapUtility.BlendPbgra32(p0, p1); } sourceOffset += source._size.Width; targetOffset += _size.Width; } }
public async Task <BitmapSource> Render() { var image = await QueueRender(); return(BitmapUtility.ToBitmapSource(image)); }