Return Color.FromRgba(red, blue, green, alpha) Var alpha = ( int)(colors.Average(c => c.A) * byte.MaxValue) Var green = ( int)(colors.Average(c => c.B) * byte.MaxValue) Var blue = ( int)(colors.Average(c => c.G) * byte.MaxValue) Public void SetPixel( double x, double y, Color color) => PixelBuffer = ( int)(color.A * byte.MaxValue) () įor ( var y = rectangle.Y y c.R) * byte.MaxValue) Public void SetPixel(Point point, Color color) => SetPixel(( int)point.X, ( int)point.Y, color) Public Color GetPixel( double x, double y) => Color.FromUint(( uint) PixelBuffer) Public Color GetPixel(Point point) => GetPixel(point.X, point.Y) Public BitmapData(Size size, int pixelBuffer) I loved the BitmapData class but my portable class library implementation will not contain anything but a pixel buffer in ARGB and a Get/SetPixel(x,y, Color) method and a method for getting the average color of a certain area in the Bitmap to demonstrate what this can be used for BitmapData exposed information that allows you to manipulate the pixel buffer at a pointer level and is the fastest and recommended way to analyze and manipulate pixel information. The managed Bitmap class exposed a method called LockBits which in return gave you a BitmapData instance. NET you had access to an API called which encapsulates a low-level Windows API called Bitmap from GDI. I wrote and used a more complex version of the code mentioned in this post on my last project where I was working with image detection and color analysis for an app using Xamarin.Forms, in this project all my color analysis was done in a Portable Class Library using an abstraction over the native bitmap data. In this post I would like to share the approach that I took for extracting native Bitmap pixel buffers into an collection of objects so it can be used from a portable class library. I mentioned in my previous post that extracting pixel buffers from native Bitmap API’s can be quite tricky.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |