How to sharpen a bitmap?

Now I am developing an Android application in Xamarin and I am stuck in a small step. I was looking for interwebs for pointy alogrithm for MonoDroid, and everything I find does not seem to work. Can someone provide me with some kind of script document or some documentation? Thanks in advance.

0
c # xamarin xamarin.android
source share
2 answers

Mohit's excellent answer targets the .NET System.Drawing.Bitmap class. Android has a different drawing class and color representation. You can find the color documentation here: https://developer.xamarin.com/api/type/Android.Graphics.Color/

Values ​​A, R, G, and B from the color can be obtained using:

int color = bitmap.GetPixel(x, y); var androidColor = new Color(color); byte r = androidColor.R; byte g = androidColor.G; byte b = androidColor.B; byte alpha = androidColor.A; 

It should be possible to use the provided algorithm as is with these changes in place.

+1
source share

It may be useful for you.

 public static Bitmap ImageSharpen(Bitmap InpImg) { Bitmap sharpenImage = new Bitmap(InpImg.Width, InpImg.Height); int wdth = InpImg.Width; int hght = InpImg.Height; double[,] filter = new double[3, 3]; filter[0, 0] = filter[0, 1] = filter[0, 2] = filter[1, 0] = filter[1, 2] = filter[2, 0] = filter[2, 1] = filter[2, 2] = -1; filter[1, 1] = 9; double factor = 1.0; double bias = 0.0; Color[,] result = new Color[InpImg.Width, InpImg.Height]; for (int x = 0; x < wdth; ++x) { for (int y = 0; y < hght; ++y) { double red = 0.0, green = 0.0, blue = 0.0; Color imageColor = InpImg.GetPixel(x, y); for (int filterX = 0; filterX < 3; filterX++) { for (int filterY = 0; filterY < 3; filterY++) { int imageX = (x - 3 / 2 + filterX + wdth) % wdth; int imageY = (y - 3 / 2 + filterY + hght) % hght; Color imageColor = InpImg.GetPixel(imageX, imageY); red += imageColor.R * filter[filterX, filterY]; green += imageColor.G * filter[filterX, filterY]; blue += imageColor.B * filter[filterX, filterY]; } int r = Math.Min(Math.Max((int)(factor * red + bias), 0), 255); int g = Math.Min(Math.Max((int)(factor * green + bias), 0), 255); int b = Math.Min(Math.Max((int)(factor * blue + bias), 0), 255); result[x, y] = Color.FromArgb(r, g, b); } } } for (int i = 0; i < wdth; ++i) { for (int j = 0; j < hght; ++j) { sharpenImage.SetPixel(i, j, result[i, j]); } } return sharpenImage; } 
+1
source share

All Articles