本文整理汇总了C#中System.GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetPixel方法的具体用法?C# System.GetPixel怎么用?C# System.GetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDiff
static int GetDiff(System.Drawing.Bitmap origin, System.Drawing.Bitmap target)
{
int sum = 0;
for (int y = 0; y < Math.Max(origin.Height, target.Height); y++)
{
for (int x = 0; x < Math.Max(origin.Width, target.Width); x++)
{
System.Drawing.Color co = new System.Drawing.Color();
System.Drawing.Color ct = new System.Drawing.Color();
if ( origin.Width > x &&
origin.Height > y)
{
co = origin.GetPixel(x, y);
}
if (target.Width > x &&
target.Height > y)
{
ct = target.GetPixel(x, y);
}
sum += (Math.Abs(co.R - ct.R) + Math.Abs(co.G - ct.G) + Math.Abs(co.B - ct.B) + Math.Abs(co.A - ct.A));
}
}
return sum;
}
示例2: DrawCharacter
private System.Drawing.Bitmap DrawCharacter(System.Drawing.Bitmap bmp, System.Drawing.Color color, int size)
{
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
System.Drawing.Color pixel = bmp.GetPixel(x, y);
if (pixel != System.Drawing.Color.FromArgb(0, 0, 0, 0))
{
if (pixel == System.Drawing.Color.FromArgb(255, 249, 249, 249))
bmp.SetPixel(x, y, System.Drawing.Color.White);
else
{
int red = (pixel.R + color.R) / 2;
int green = (pixel.G + color.G) / 2;
int blue = (pixel.B + color.B) / 2;
bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(red,
green,
blue));
}
}
}
}
System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(size, size);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImage))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, size, size));
}
return newImage;
}
示例3: GetHeightMap
public static byte[] GetHeightMap(System.Drawing.Bitmap bm)
{
byte[] result = new byte[bm.Height * bm.Width];
for (int x = 0; x < bm.Width; x++)
{
for (int y = 0; y < bm.Height; y++)
{
result[x + y * bm.Width] = bm.GetPixel(x, y).R;
}
}
return result;
}
示例4: bitmapToColorArray
/// <summary>
/// Convets Bitmaps to color Sifteo.Color array.
/// </summary>
/// <returns>
/// The to color array.
/// </returns>
/// <param name='bitmap'>
/// Bitmap.
/// </param>
public Sifteo.Color[,] bitmapToColorArray (System.Drawing.Bitmap bitmap)
{
Sifteo.Color[,] colors = new Sifteo.Color[bitmap.Width,bitmap.Height];
for (int i =0; i < bitmap.Width; i++)
{
for (int j=0; j < bitmap.Height; j++)
{
System.Drawing.Color c = bitmap.GetPixel (i, j);
colors [i,j] = new Sifteo.Color (c.R, c.G, c.B);
}
}
return colors;
}
示例5: ConvertImageToLEDArray
public static List<LED_Set> ConvertImageToLEDArray(int Light_Count, System.Drawing.Bitmap BitmapImage)
{
List<LED_Set> loaded_animation = new List<LED_Set> ();
loaded_animation.Clear ();
System.Drawing.Color CurrentColor;
for (int y = 0; y < BitmapImage.Height; y++) {
loaded_animation.Add (new LED_Set ());
for (int x = 0; x < Light_Count; x++) {
CurrentColor = BitmapImage.GetPixel (x, y);
loaded_animation [y].LED_Values.Add (new LED (CurrentColor.R, CurrentColor.G, CurrentColor.B));
}
}
return loaded_animation;
}
示例6: measureTrimmingRect
/// <summary>
/// 周囲の黒い部分を除いた部分の範囲を返す
/// </summary>
/// <param name="bitmap">処理対象の画像</param>
/// <returns>中央のマップ部分の範囲</returns>
private static System.Drawing.Rectangle measureTrimmingRect(System.Drawing.Bitmap bitmap)
{
Contract.Requires<ArgumentNullException>(bitmap != null);
var result = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
var trimColor = System.Drawing.Color.Black;
int centerX = bitmap.Width / 2, centerY = bitmap.Height / 2;
if (compareSimilarColor(trimColor, bitmap.GetPixel(centerX, centerY))) {
return result;
}
while (++result.X < bitmap.Width) {
if (!compareSimilarColor(trimColor, bitmap.GetPixel(result.X, centerY))) {
break;
}
}
while (++result.Y < bitmap.Height) {
if (!compareSimilarColor(trimColor, bitmap.GetPixel(centerX, result.Y))) {
break;
}
}
for (int right = bitmap.Width-1; right > result.X; --right) {
if (!compareSimilarColor(trimColor, bitmap.GetPixel(right, centerY))) {
result.Width = right + 1 - result.X;
break;
}
}
for (int bottom = bitmap.Height-1; bottom > result.Y; --bottom) {
if (!compareSimilarColor(trimColor, bitmap.GetPixel(centerX, bottom))) {
result.Height = bottom + 1 - result.Y;
break;
}
}
return result;
}
示例7: CreateFromBitmap
public static Image CreateFromBitmap(System.Drawing.Bitmap bm)
{
Image imm = new Image();
imm.HRes = bm.Width;
imm.VRes = bm.Height;
imm.Pixels = new Vector3[imm.VRes * imm.HRes];
for (int x = 0; x < imm.HRes; x++)
{
for (int y = 0; y < imm.VRes; y++)
{
var c = bm.GetPixel(x, y);
imm.Pixels[x + y * imm.HRes] = new Vector3((((float)c.R) / 255.0f), (((float)c.G) / 255.0f), (((float)c.B) / 255.0f));
}
}
return imm;
}
示例8: BitMapToColors
public static System.Drawing.Color[][] BitMapToColors(System.Drawing.Bitmap pic)
{
// System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pic.Length.Length, pic[0].Length);
System.Drawing.Color[][] ret;
ret = new System.Drawing.Color[pic.Width][];
for (int w = 0; w < pic.Width; w++)
{
ret[w]= new System.Drawing.Color[pic.Height];
for (int h = 0; h < pic.Height; h++)
ret[w][h] = pic.GetPixel(w, h);
}
return ret;
}
示例9: BitMapToColorsArray
public static System.Drawing.Color[,] BitMapToColorsArray(System.Drawing.Bitmap pic)
{
System.Drawing.Color[,] ret;
ret = new System.Drawing.Color[pic.Height, pic.Width];
for (int w = 0; w < pic.Width; w++)
{
// ret[w] = new System.Drawing.Color[pic.Height];
for (int h = 0; h < pic.Height; h++)
ret[h,w] = pic.GetPixel(w, h);
}
return ret;
}
示例10: BitmapToBlackWhite2
public System.Drawing.Bitmap BitmapToBlackWhite2(System.Drawing.Bitmap src)
{
double treshold = 0.6;
Bitmap dst = new Bitmap(src.Width, src.Height);
for (int i = 0; i < src.Width; i++)
{
for (int j = 0; j < src.Height; j++)
{
dst.SetPixel(i, j, src.GetPixel(i, j).GetBrightness() < treshold ? System.Drawing.Color.Black : System.Drawing.Color.White);
}
}
return dst;
}
示例11: LoadBitmap
public static Bitmap LoadBitmap(System.Drawing.Bitmap bmp)
{
int w = bmp.Width;
int h = bmp.Height;
Bitmap result = new Bitmap(w, h);
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
System.Drawing.Color pixel = bmp.GetPixel(x, y);
int argb = pixel.ToArgb();
int col = (argb & 0xf) >> 2;
if (pixel.A == 255 && pixel.R == 255 && pixel.G == 0 && pixel.B == 255) col = -1;
result.pixels[x + y * w] = col;
}
}
return result;
}
示例12: BitmapToSurface
ImageSurface BitmapToSurface(System.Drawing.Bitmap bmp)
{
Int32[] data = new Int32[bmp.Width * bmp.Height];
for (int y = 0; y < bmp.Height; y++)
for (int x = 0; x < bmp.Width; x++)
{
System.Drawing.Color col = bmp.GetPixel(x, y);
data[x + y * bmp.Width] = col.ToArgb();
}
// pin databuffer until imgSurf is destroyed
_gc_h_surface_data_buffer = System.Runtime.InteropServices.GCHandle.Alloc(data, System.Runtime.InteropServices.GCHandleType.Pinned);
// create image surface
IntPtr dataPtr = System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
ImageSurface imgSurf = new ImageSurface(dataPtr, Format.Argb32, bmp.Width, bmp.Height, bmp.Width * 32 / 8);
return imgSurf;
}
示例13: GetHistogram
public long[] GetHistogram(System.Drawing.Bitmap picture)
{
long[] myHistogram = new long[256];
for (int i = 0; i < picture.Size.Width; i++)
for (int j = 0; j < picture.Size.Height; j++)
{
System.Drawing.Color c = picture.GetPixel(i, j);
long Temp = 0;
Temp += c.R;
Temp += c.G;
Temp += c.B;
Temp = (int)Temp / 3;
myHistogram[Temp]++;
}
return myHistogram;
}
示例14: CreateMaskFromImage
public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image)
{
int width = image.Width;
int height = image.Height;
int stride = (width + 7) >> 3;
byte[] mask = new byte[stride * height];
bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
byte bit = (byte) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
int offset = y * stride + (x >> 3);
if (image.GetPixel(x, y).A >= 128)
mask[offset] |= bit;
}
}
return XCreatePixmapFromBitmapData(display, XDefaultRootWindow(display),
mask, width, height, new IntPtr(1), IntPtr.Zero, 1);
}
示例15: Image
//public Image(int width, int height)
//{
// _pixels = new Pixel[width, height];
// for (int x = 0; x < width; x++)
// for (int y = 0; y < height; y++)
// _pixels[x, y] = new Pixel(x, y);
//}
public Image(double width, double height, System.Drawing.Bitmap bitmap, Interpolators.IInterpolator interpolator)
{
if (interpolator == null)
throw new ArgumentNullException("interpolator", "interpolator is null.");
if (bitmap == null)
throw new ArgumentNullException("bitmap", "bitmap is null.");
if (Width < 0)
throw new Exception("Width can't be negative");
if (Height < 0)
throw new Exception("Height can't be negative");
Width = width;
Height = height;
_interpolator = interpolator;
ScaleHorizontal = (bitmap.Width - 1) / Width;
ScaleVertical = (bitmap.Height - 1) / Height;
_pixels = new Pixel[bitmap.Width, bitmap.Height];
for (int x = 0; x < bitmap.Width; x++)
for (int y = 0; y < bitmap.Height; y++)
_pixels[x, y] = new Pixel(bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness(), x, y);
}