本文整理汇总了C#中Android.Graphics.Bitmap.GetPixels方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetPixels方法的具体用法?C# Bitmap.GetPixels怎么用?C# Bitmap.GetPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetPixels方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Binarize
public static Bitmap Binarize(Bitmap bm, double threshhold)
{
//Binarize
int size = bm.Width * bm.Height;
int[] pixels = new int[size];
bm.GetPixels( pixels, 0, bm.Width, 0, 0, bm.Width, bm.Height );
// Calculate overall lightness of image
int c;
for (int i = 0; i < size; i++)
{
c = pixels[i];
double whiteDist = Math.Sqrt(Math.Pow(0xff - ((c&0x00FF0000 )>>16),2) + Math.Pow(0xff - ((c & 0x0000FF00 )>>8), 2) + Math.Pow(0xff - (c&0x000000FF), 2));
double blackDist = Math.Sqrt(Math.Pow(0x00 - ((c&0x00FF0000 )>>16),2) + Math.Pow(0x00 - ((c & 0x0000FF00 )>>8), 2) + Math.Pow(0x00 - (c&0x000000FF), 2));
double distance = blackDist + whiteDist;
if (whiteDist / distance > threshhold / 30.0) {
pixels [i] = Color.Black;
} else {
pixels [i] = Color.White;
}
}
Bitmap newBitmap = bm.Copy (bm.GetConfig (), true);
newBitmap.SetPixels (pixels, 0, bm.Width, 0, 0, bm.Width, bm.Height);
return newBitmap;
}
示例2: ChangeColor
private static Bitmap ChangeColor(Bitmap bitmap, Color fromColor, Color targetColor, float tolerance = 20)
{
int width = bitmap.Width;
int height = bitmap.Height;
int[] pixels = new int[width * height];
float[] redRange = new float[2]{
(float)Math.Max(fromColor.R - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.R + (tolerance / 2), 255.0)};
float[] greenRange = new float[2]{
(float)Math.Max(fromColor.G - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.G + (tolerance / 2), 255.0)};
float[] blueRange = new float[2]{
(float)Math.Max(fromColor.B - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.B + (tolerance / 2), 255.0)};
bitmap.GetPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < pixels.Length; i++)
{
if (pixels[i] == fromColor)
{
pixels[i] = new Color(targetColor.R, targetColor.G, targetColor.B, targetColor.A - 1);
}
int red = Color.GetRedComponent(pixels[i]);
int green = Color.GetGreenComponent(pixels[i]);
int blue = Color.GetBlueComponent(pixels[i]);
int alpha = Color.GetAlphaComponent(pixels[i]);
if (((red >= redRange[0]) && (red <= redRange[1])) &&
((green >= greenRange[0]) && (green <= greenRange[1])) &&
((blue >= blueRange[0]) && (blue <= blueRange[1])) &&
((alpha > 0 && alpha < 254)))
{
pixels[i] = new Color(targetColor.R, targetColor.G, targetColor.B, targetColor.A - 1);
}
}
if (bitmap.IsMutable)
{
bitmap.SetPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
else
{
var mutableBitmap = bitmap.Copy(bitmap.GetConfig(), true);
mutableBitmap.SetPixels(pixels, 0, width, 0, 0, width, height);
return mutableBitmap;
}
}
示例3: BitmapLuminanceSource
/// <summary>
/// Initializes a new instance of the <see cref="BitmapLuminanceSource"/> class.
/// </summary>
/// <param name="bitmap">The bitmap.</param>
public BitmapLuminanceSource(Bitmap bitmap)
: base(bitmap.Width, bitmap.Height)
{
// get all pixels at once from the bitmap (should be one of the fastest ways to analyze the whole picture)
var pixels = new int[bitmap.Width * bitmap.Height];
bitmap.GetPixels(pixels, 0, bitmap.Width, 0, 0, bitmap.Width, bitmap.Height);
// convert the pixel array to a byte array because the underlying method of
// RGBLuminanceSource doesn't support an int array
var pixelBytes = new byte[pixels.Length * 4];
Buffer.BlockCopy(pixels, 0, pixelBytes, 0, pixelBytes.Length);
// calculating the luminance values the same way as RGBLuminanceSource
CalculateLuminance(pixelBytes, BitmapFormat.RGB32);
}
示例4: CreateOverlayedBitmap
private static Bitmap CreateOverlayedBitmap(Bitmap bitmap, int width, int height)
{
int[] originalPixels = new int[bitmap.Width * bitmap.Height];
bitmap.GetPixels(originalPixels, 0, bitmap.Width, 0, 0, bitmap.Width, bitmap.Height);
int[] pixels = new int[width * height];
int xStart = (width - bitmap.Width) / 2;
int xEnd = (width + bitmap.Width) / 2;
for (int y = 0; y < height; y++)
{
int rowStart = y*width;
int originalRowStart = y*bitmap.Width;
for (int ox = 0, x = xStart; x < xEnd; x++, ox++)
{
pixels[rowStart + x] = originalPixels[originalRowStart + ox];
}
}
return Bitmap.CreateBitmap(pixels, width, height, bitmap.GetConfig());
}
示例5: RGB565toARGB888
Bitmap RGB565toARGB888(Bitmap img)
{
int numPixels = img.Width * img.Height;
//Create a Bitmap of the appropriate format.
if (tmp == null)
{
tmp = Bitmap.CreateBitmap(img.Width, img.Height, Bitmap.Config.Argb8888);
pixels = new int[numPixels];
}
//Get JPEG pixels. Each int is the color values for one pixel.
img.GetPixels(pixels, 0, img.Width, 0, 0, img.Width, img.Height);
//Set RGB pixels.
tmp.SetPixels(pixels, 0, tmp.Width, 0, 0, tmp.Width, tmp.Height);
return tmp;
}
示例6: GetBlurredBitmap
// This code is a C# port of the Java code which can be found at:
// http://www.java2s.com/Code/Android/2D-Graphics/Generateablurredbitmapfromgivenone.htm
//
// The following code is another example (Java based):
// http://incubator.quasimondo.com/processing/stackblur.pde
public Bitmap GetBlurredBitmap(Bitmap original, int radius)
{
if (radius < 1)
{
throw new ArgumentOutOfRangeException("radius", "Radius must be > =1.");
}
int width = original.Width;
int height = original.Height;
int wm = width - 1;
int hm = height - 1;
int wh = width * height;
int div = radius + radius + 1;
int[] r = new int[wh];
int[] g = new int[wh];
int[] b = new int[wh];
int rsum, gsum, bsum, x, y, i;
int p1, p2;
int[] vmin = new int[Math.Max(width, height)];
int[] vmax = new int[Math.Max(width, height)];
int[] dv = new int[256 * div];
for (i = 0; i < 256 * div; i++)
{
dv[i] = i / div;
}
int[] blurredBitmap = new int[wh];
original.GetPixels(blurredBitmap, 0, width, 0, 0, width, height);
int yw = 0;
int yi = 0;
for (y = 0; y < height; y++)
{
rsum = 0;
gsum = 0;
bsum = 0;
for (i = -radius; i <= radius; i++)
{
int p = blurredBitmap[yi + Math.Min(wm, Math.Max(i, 0))];
rsum += (p & 0xff0000) >> 16;
gsum += (p & 0x00ff00) >> 8;
bsum += p & 0x0000ff;
}
for (x = 0; x < width; x++)
{
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
if (y == 0)
{
vmin[x] = Math.Min(x + radius + 1, wm);
vmax[x] = Math.Max(x - radius, 0);
}
p1 = blurredBitmap[yw + vmin[x]];
p2 = blurredBitmap[yw + vmax[x]];
rsum += ((p1 & 0xff0000) - (p2 & 0xff0000)) >> 16;
gsum += ((p1 & 0x00ff00) - (p2 & 0x00ff00)) >> 8;
bsum += (p1 & 0x0000ff) - (p2 & 0x0000ff);
yi++;
}
yw += width;
}
for (x = 0; x < width; x++)
{
rsum = gsum = bsum = 0;
int yp = -radius * width;
for (i = -radius; i <= radius; i++)
{
yi = Math.Max(0, yp) + x;
rsum += r[yi];
gsum += g[yi];
bsum += b[yi];
yp += width;
}
yi = x;
for (y = 0; y < height; y++)
{
blurredBitmap[yi] = (int)(0xff000000 | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]);
if (x == 0)
{
vmin[y] = Math.Min(y + radius + 1, hm) * width;
vmax[y] = Math.Max(y - radius, 0) * width;
}
p1 = x + vmin[y];
p2 = x + vmax[y];
rsum += r[p1] - r[p2];
gsum += g[p1] - g[p2];
bsum += b[p1] - b[p2];
yi += width;
}
//.........这里部分代码省略.........
示例7: Blur
public static void Blur(Bitmap original, Bitmap blurred, int radius)
{
if (radius < 1)
{
throw new ArgumentOutOfRangeException("radius", "Radius must be > 0.");
}
int width = original.Width;
int height = original.Height;
int wm = width - 1;
int hm = height - 1;
int wh = width * height;
int div = radius + radius + 1;
int[] a = new int[wh];
int[] r = new int[wh];
int[] g = new int[wh];
int[] b = new int[wh];
int asum, rsum, gsum, bsum;
int x, y, i;
int p1, p2;
int[] vmin = new int[Math.Max(width, height)];
int[] vmax = new int[Math.Max(width, height)];
int[] dv = new int[256 * div];
for (i = 0; i < 256 * div; i++)
{
dv[i] = i / div;
}
int[] blurredBitmap = new int[wh];
original.GetPixels(blurredBitmap, 0, width, 0, 0, width, height);
Premultiply(blurredBitmap);
int yw = 0;
int yi = 0;
for (y = 0; y < height; y++)
{
asum = 0;
rsum = 0;
gsum = 0;
bsum = 0;
for (i = -radius; i <= radius; i++)
{
int p = blurredBitmap[yi + Math.Min(wm, Math.Max(i, 0))];
asum += A(p);
rsum += R(p);
gsum += G(p);
bsum += B(p);
}
for (x = 0; x < width; x++)
{
a[yi] = dv[asum];
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
if (y == 0)
{
vmin[x] = Math.Min(x + radius + 1, wm);
vmax[x] = Math.Max(x - radius, 0);
}
p1 = blurredBitmap[yw + vmin[x]];
p2 = blurredBitmap[yw + vmax[x]];
asum += A(p1) - A(p2);
rsum += R(p1) - R(p2);
gsum += G(p1) - G(p2);
bsum += B(p1) - B(p2);
yi++;
}
yw += width;
}
for (x = 0; x < width; x++)
{
asum = rsum = gsum = bsum = 0;
int yp = -radius * width;
for (i = -radius; i <= radius; i++)
{
yi = Math.Max(0, yp) + x;
asum += a[yi];
rsum += r[yi];
gsum += g[yi];
bsum += b[yi];
yp += width;
}
yi = x;
for (y = 0; y < height; y++)
{
blurredBitmap[yi] = (dv[asum] << 24) | (dv[rsum] << 16) | (dv[gsum] << 8) | (dv[bsum]);
if (x == 0)
{
vmin[y] = Math.Min(y + radius + 1, hm) * width;
vmax[y] = Math.Max(y - radius, 0) * width;
}
p1 = x + vmin[y];
p2 = x + vmax[y];
asum += a[p1] - a[p2];
//.........这里部分代码省略.........