本文整理汇总了C#中System.Drawing.Bitmap.GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetPixel方法的具体用法?C# Bitmap.GetPixel怎么用?C# Bitmap.GetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
public static void Remove(int colour, ref Bitmap bp)
{
Color c;
switch (colour)
{
case BLUE:
for (int i = 1; i < bp.Width; i++)
for (int j = 1; j < bp.Height; j++)
{
c = bp.GetPixel(i, j);
bp.SetPixel(i, j, Color.FromArgb(c.R, c.G, 0));
}
break;
case RED:
for (int i = 1; i < bp.Width; i++)
for (int j = 1; j < bp.Height; j++)
{
c = bp.GetPixel(i, j);
bp.SetPixel(i, j, Color.FromArgb(0, c.G, c.B));
}
break;
case GREEN:
for (int i = 1; i < bp.Width; i++)
for (int j = 1; j < bp.Height; j++)
{
c = bp.GetPixel(i, j);
bp.SetPixel(i, j, Color.FromArgb(c.R, 0, c.B));
}
break;
}
}
示例2: Binariz
public Bitmap Binariz(Bitmap bm)
{
int x = bm.Width;
int y = bm.Height;
Bitmap result = new Bitmap(x, y);
for (int pixX = 0; pixX < x; pixX++)
for (int pixY = 0; pixY < y; pixY++)
{
int rd, gr, bl;
if (bm.GetPixel(pixX, pixY).R < 100)
rd = 0;
else
rd = 255;
if (bm.GetPixel(pixX, pixY).G < 100)
gr = 0;
else
gr = 255;
if (bm.GetPixel(pixX, pixY).B < 100)
bl = 0;
else
bl = 255;
result.SetPixel(pixX, pixY, Color.FromArgb((byte)rd, (byte)gr, (byte)bl));
}
return result;
}
示例3: CalculateGraphicsPathFromBitmap
// From http://edu.cnzz.cn/show_3281.html
public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap, Color colorTransparent)
{
GraphicsPath graphicsPath = new GraphicsPath();
if (colorTransparent == Color.Empty)
colorTransparent = bitmap.GetPixel(0, 0);
for(int row = 0; row < bitmap.Height; row ++)
{
int colOpaquePixel = 0;
for(int col = 0; col < bitmap.Width; col ++)
{
if(bitmap.GetPixel(col, row) != colorTransparent)
{
colOpaquePixel = col;
int colNext = col;
for(colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++)
if(bitmap.GetPixel(colNext, row) == colorTransparent)
break;
graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
col = colNext;
}
}
}
return graphicsPath;
}
示例4: IsEmptyBitmap
private bool IsEmptyBitmap (Bitmap bitmap, out int x, out int y)
{
bool result = true;
int empty = Color.Empty.ToArgb ();
#if false
for (y = 0; y < bitmap.Height; y++) {
for (x = 0; x < bitmap.Width; x++) {
if (bitmap.GetPixel (x, y).ToArgb () != empty) {
Console.Write ("X");
result = false;
} else
Console.Write (" ");
}
Console.WriteLine ();
}
#else
for (y = 0; y < bitmap.Height; y++) {
for (x = 0; x < bitmap.Width; x++) {
if (bitmap.GetPixel (x, y).ToArgb () != empty)
return false;
}
}
#endif
x = -1;
y = -1;
return result;
}
示例5: Filter
//метод простой бинаризации, пока не используется, в дальнейшем - с помощью него будет происходить бинар-я с заданным порогом
public Bitmap Filter(Bitmap originalBitmap)
{
int treshold = 0; // порог
Color color; // цвет - будет разбиваться на RGB
int average = 0; // средний цвет = яркость
Bitmap resultBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height);
for (int i = 0; i < originalBitmap.Width; i++)
{
for (int j = 0; j < originalBitmap.Height; j++)
{
color = originalBitmap.GetPixel(i, j);
average = (int)(color.R + color.G + color.B) / 3;
treshold = treshold + average;
}
}
treshold = treshold / (originalBitmap.Width * originalBitmap.Height);
for (int i = 0; i < originalBitmap.Width; i++)
{
for (int j = 0; j < originalBitmap.Height; j++)
{
color = originalBitmap.GetPixel(i, j);
average = (int)(color.R + color.G + color.B) / 3;
resultBitmap.SetPixel(i, j, average < treshold ? Color.Black : Color.White);
}
}
return resultBitmap;
}
示例6: Filter
public Bitmap Filter(Bitmap originalBitmap)
{
Bitmap resultBitmap = new Bitmap(originalBitmap);
Color color;
for (int i = SIZE; i < originalBitmap.Width - SIZE; i++)
{
for (int j = SIZE; j < originalBitmap.Height - SIZE; j++)
{
List<int> redList = new List<int>();
List<int> greenList = new List<int>();
List<int> blueList = new List<int>();
int red = 0, green = 0, blue = 0;
for (int ii = -SIZE; ii < SIZE + 1; ii++)
{
for (int jj = -SIZE; jj < SIZE + 1; jj++)
{
color = originalBitmap.GetPixel(i + ii, j + jj);
redList.Add(color.R);
greenList.Add(color.G);
blueList.Add(color.B);
}
}
redList.Sort();
greenList.Sort();
blueList.Sort();
red = redList.ElementAt(SIZE);
green = greenList.ElementAt(SIZE);
blue = blueList.ElementAt(SIZE);
color = originalBitmap.GetPixel(i, j);
color = Color.FromArgb(color.A, FilterService.SetColor(red), FilterService.SetColor(green), FilterService.SetColor(blue));
resultBitmap.SetPixel(i, j, color);
}
}
return resultBitmap;
}
示例7: binarize
private void binarize(Bitmap bittt, ref int[,] massss, ToolStripProgressBar progress)
{
massss = new int[bittt.Width, bittt.Height];
progress.Minimum = 0;
progress.Maximum = bittt.Height;
for (int i = 0; i < bittt.Height; i++)
{
for (int j = 0; j < bittt.Width; j++)
{
if (bittt.GetPixel(j, i).R > 200 || bittt.GetPixel(j, i).B > 200 || bittt.GetPixel(j, i).G > 200)
{
bittt.SetPixel(j, i, Color.White);
massss[j, i] = 0;
}
else
{
bittt.SetPixel(j, i, Color.Black);
massss[j, i] = 1;
}
/* if (j == (int)(bittt.Height / 6))
{
bittt.SetPixel(j, i, Color.Teal);
}*/
}
if (progress.Value < bittt.Height)
{
progress.Value++;
}
}
progress.Value = 0;
}
示例8: testEdgeDetection
public void testEdgeDetection()
{
String testPath = "testEdge/";
String[] pictures = Directory.GetFiles(testPath);
EdgeDetector eD = new EdgeDetector(testPath);
eD.execute();
String directory = "Edged/";
String[] edgedPictures = Directory.GetFiles(directory);
Assert.AreEqual(edgedPictures.Length, pictures.Length, "Some images were not preccessed in Edge Detection");
int edgedCount = 0;
for (int i = 0; i < edgedPictures.Length; i++)
{
bool isBlackOrWhite = true;
Bitmap finalImages = new Bitmap(edgedPictures[i]);
for (int j = 0; j < finalImages.Width; j++)
{
for (int k = 0; k < finalImages.Height; k++)
{
if(finalImages.GetPixel(j,k).R > 0 && finalImages.GetPixel(j,k).R < 255)
{
isBlackOrWhite = false;
break;
}
}
if(!isBlackOrWhite)
break;
}
if (isBlackOrWhite)
edgedCount++;
Assert.AreEqual(true, isBlackOrWhite, "Image is not an edged image");
}
Assert.AreEqual(edgedPictures.Length, edgedCount, "Not all images were Edged");
}
示例9: button2_Click
private void button2_Click(object sender, EventArgs e)
{
diff = (int)this.numericUpDown1.Value;
Bitmap sourceBmp = new Bitmap(this.pictureBox1.Image);
Bitmap targetBmp = new Bitmap(sourceWidth, sourceHeight);
for (int x = 0; x < sourceWidth; x++)
{
for (int y = 0; y < sourceHeight; y++)
{
Color curColor = sourceBmp.GetPixel(x, y);
List<Point> testPoints = new List<Point>(8);
//testPoints.Add(new Point(x - 1, y - 1));
//testPoints.Add(new Point(x, y - 1));
testPoints.Add(new Point(x + 1, y - 1));
//testPoints.Add(new Point(x, y));
testPoints.Add(new Point(x + 1, y));
//testPoints.Add(new Point(x - 1, y + 1));
testPoints.Add(new Point(x, y + 1));
testPoints.Add(new Point(x + 1, y + 1));
foreach (Point p in testPoints)
{
if (InsideImg(p))
if (IsBeyondDiff(sourceBmp.GetPixel(p.X, p.Y), curColor))
{
targetBmp.SetPixel(x, y, Color.Black);
break;
}
}
}
}
this.pictureBox2.Image = targetBmp;
}
示例10: LoadFavs
private Task LoadFavs()
{
return Task.Factory.StartNew(() =>
{
Dispatcher.BeginInvoke((Action) (async () =>
{
try
{
var request =
(HttpWebRequest) WebRequest.Create("http://www.google.com/s2/favicons?domain=" + _url);
var response = await request.GetResponseAsync();
var responseStream = response.GetResponseStream();
var bmp = new Bitmap(responseStream);
var brush = new SolidColorBrush(StaticFunctions.ToMediaColor(bmp.GetPixel(11, 11)));
Grid.Background = brush;
image.Source = BitmapToImageSource(bmp);
var foreColor = PerceivedBrightness(StaticFunctions.ToMediaColor(bmp.GetPixel(11, 11))) > 130
? Brushes.Black
: Brushes.White;
label.Foreground = foreColor;
}
catch
{
}
}));
});
}
示例11: BitmapToDoubleArray
public static int[][] BitmapToDoubleArray(Bitmap fileBitmap, string extension)
{
int[][] uploadedDocument;
int width = fileBitmap.Width;
int height = fileBitmap.Height;
uploadedDocument = new int[width][];
for (int i = 0; i < width; i++)
uploadedDocument[i] = new int[height];
Color pixelColor;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
switch(extension){
case ".bmp":
pixelColor = fileBitmap.GetPixel(i, j);
uploadedDocument[i][j] = (int)(pixelColor.R * 0.3 + pixelColor.G * 0.59 + pixelColor.B * 0.11);
break;
case ".png":
uploadedDocument[i][j] = (255 - (int)fileBitmap.GetPixel(i,j).A);
break;
}
}
}
return uploadedDocument;
}
示例12: encode
public static Bitmap encode(Bitmap img, int offSet)
{
Bitmap newImage = new Bitmap(img.Width * offSet, img.Height * offSet);
List<List<Color>> pixelMap = new List<List<Color>>();
for (int y = 0; y < img.Height; y++)
{
List<Color> row = new List<Color>();
for (int x = 0; x < img.Width; x++)
{
row.Add(img.GetPixel(x, y));
}
pixelMap.Add(row);
}
Random r = new Random();
for (int y = 0; y < newImage.Height; y++)
{
for (int x = 0; x < newImage.Width; x++)
{
if (x % offSet == 0 && y % offSet == 0)
{
newImage.SetPixel(x, y, pixelMap[y / offSet][x / offSet]);
}
else
{
newImage.SetPixel(x, y, img.GetPixel(r.Next(0, img.Width - 1), r.Next(0, img.Height - 1)));
}
}
}
return newImage;
}
示例13: UniformQuantization
public static Bitmap UniformQuantization(Bitmap bmp, int kR, int kG, int kB)
{
int[] red, green, blue;
int r, g, b;
Bitmap res = new Bitmap(bmp.Width, bmp.Height);
//podziel red
red = DividePalette(kR);
//podziel green
green = DividePalette(kG);
//podziel blue
blue = DividePalette(kB);
for (int i = 0; i < bmp.Width; ++i)
for (int j = 0; j < bmp.Height; ++j)
{
r = FindClosest(red, bmp.GetPixel(i, j).R);
g = FindClosest(green, bmp.GetPixel(i, j).G);
b = FindClosest(blue, bmp.GetPixel(i, j).B);
res.SetPixel(i, j, Color.FromArgb(r, g, b));
}
return res;
}
示例14: write_Bmp_To_RGB_Number
/// <summary>
/// Save source bitmap image as text which contains all positions' pixel value
/// random position value = {R, G, B}
/// </summary>
/// <param name="sourceImage"></param>
/// <param name="path"></param>
public static void write_Bmp_To_RGB_Number(Bitmap sourceImage, string path)
{
try
{
int i = 0, j = 0;
StreamWriter sw = new StreamWriter(path);
for (j = 0; j < sourceImage.Height; j++)
{
for (i = 0; i < sourceImage.Width; i++)
{
sw.Write("({0},{1},{2}) ",
sourceImage.GetPixel(i, j).R.ToString().PadLeft(3, '0').Replace("255", " "),
sourceImage.GetPixel(i, j).G.ToString().PadLeft(3, '0').Replace("255", " "),
sourceImage.GetPixel(i, j).B.ToString().PadLeft(3, '0').Replace("255", " "));
}
sw.WriteLine();
}
sw.Flush();
sw.Close();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
示例15: convertToTXT
public static int[] convertToTXT(Bitmap img)
{
double averageBrightness = 0;
for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++)
{
averageBrightness += img.GetPixel(x, y).R;
}
}
averageBrightness /= (img.Width * img.Height);
int[] result = new int[img.Width * img.Height];
for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++)
{
if (img.GetPixel(x, y).R < averageBrightness)
result[img.Width * y + x] = 0;
else
result[img.Width * y + x] = 1;
}
}
return result;
}