本文整理汇总了C#中System.Drawing.Bitmap.SetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.SetPixel方法的具体用法?C# Bitmap.SetPixel怎么用?C# Bitmap.SetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.SetPixel方法的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: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
//read source image
Bitmap simg = new Bitmap("D:\\Image\\audrey.jpg");
//get source image dimension
int width = simg.Width;
int height = simg.Height;
//load source image in picturebox1
pictureBox1.Image = Image.FromFile("D:\\Image\\audrey.jpg");
//mirror image
Bitmap mimg = new Bitmap(width * 2, height);
for (int y = 0; y < height; y++)
{
for (int lx = 0, rx = width * 2 - 1; lx < width; lx++, rx--)
{
//get source pixel value
Color p = simg.GetPixel(lx, y);
//set mirror pixel value
mimg.SetPixel(lx, y, p);
mimg.SetPixel(rx, y, p);
}
}
//load mirror image in picturebox2
pictureBox2.Image = mimg;
//save (write) mirror image
mimg.Save("D:\\Image\\MirrorImage.png");
}
示例3: MyClassInitialize
public static void MyClassInitialize(TestContext testContext)
{
Greyscale conv = new Greyscale();
testBitmap = new Bitmap(testPixel, testPixel);
for (int height = 0; height < testBitmap.Height; height++)
{
for (int width = 0; width < testBitmap.Width; width++)
{
testBitmap.SetPixel(width, height, Color.White);
width++;
testBitmap.SetPixel(width, height, Color.Black);
width++;
testBitmap.SetPixel(width, height, Color.Red);
width++;
testBitmap.SetPixel(width, height, Color.Green);
width++;
testBitmap.SetPixel(width, height, Color.Blue);
}
}
//create greyscale
double[] newColorValues = new double[3];
for (int i = 0; i < newColorValues.GetLength(0); i++)
{
newColorValues[i] = 1;
}
fullGrey = new Memento("Blur", newColorValues);
//get greyscaled Bitmap
original = conv.getMemento();
conv.setMemento(fullGrey);
processedBitmap = conv.process(testBitmap);
conv.setMemento(original);
}
示例4: GenerateCode
//-------------------------------------------------------------------------------------------
public static Bitmap GenerateCode(string data, int size)
{
QRCodeWriter writer = new QRCodeWriter();
com.google.zxing.common.ByteMatrix matrix;
matrix = writer.encode(data, BarcodeFormat.QR_CODE, size, size, null);
Bitmap img = new Bitmap(size, size);
Color Color = Color.FromArgb(0, 0, 0);
for (int y = 0; y < matrix.Height; ++y)
{
for (int x = 0; x < matrix.Width; ++x)
{
Color pixelColor = img.GetPixel(x, y);
//Find the colour of the dot
if (matrix.get_Renamed(x, y) == -1)
{
img.SetPixel(x, y, Color.White);
}
else
{
img.SetPixel(x, y, Color.Black);
}
}
}
return img;
}
示例5: GetThumbnail
public static Bitmap GetThumbnail(Bitmap bmpImage, Size size)
{
double width = bmpImage.Width;
double height = bmpImage.Height;
Double xFactor = new Double();
Double yFactor = new Double();
xFactor = (double)size.Width / width;
yFactor = (double)size.Height / height;
Double scaleFactor = Math.Min(xFactor, yFactor);
Size scaledSize = new Size();
scaledSize.Width = Convert.ToInt32(width * scaleFactor);
scaledSize.Height = Convert.ToInt32(height * scaleFactor);
Bitmap scaledOriginal = (Bitmap) bmpImage.GetThumbnailImage(scaledSize.Width, scaledSize.Height, new Image.GetThumbnailImageAbort(target), IntPtr.Zero);
Bitmap thumnailBmp = new Bitmap(size.Width, size.Height);
for (int y = 0; y < thumnailBmp.Height; y++)
{
for (int x = 0; x < thumnailBmp.Width; x++)
{
if ((x < scaledOriginal.Width) && (y < scaledOriginal.Height))
{
thumnailBmp.SetPixel(x, y, scaledOriginal.GetPixel(x, y));
}
else
{
thumnailBmp.SetPixel(x, y, Color.Transparent);
}
}
}
return thumnailBmp;
}
示例6: Img2BW
/* Convert the image into binary image*/
public Bitmap Img2BW(Bitmap imgSrc, double threshold)
{
int width = imgSrc.Width;
int height = imgSrc.Height;
int px; double br;
Color pixel;
Bitmap imgOut = new Bitmap(imgSrc);
allPoints = new Point[5000000];
for (int row = 0; row < height - 1; row++)
{
for (int col = 0; col < width - 1; col++)
{
pixel = imgSrc.GetPixel(col, row);
px = pixel.ToArgb();
br = pixel.GetBrightness();
if (pixel.GetBrightness() < threshold)
{
imgOut.SetPixel(col, row, cblack);
vertices.Add(new Vertex(col, row));
allPoints[countPoints].X = col;
allPoints[countPoints].Y = row;
countPoints++;
}
else
imgOut.SetPixel(col, row, cwhite);
}
}
return imgOut;
}
示例7: GetBitmap
public Bitmap GetBitmap()
{
Bitmap output;
using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open)))
{
int width = reader.ReadInt32();
int height = reader.ReadInt32();
output = new Bitmap(width * 8, height);
for (int y = height - 1; y >= 0; y--)
{
for (int x = 0; x < width; x++)
{
byte input = reader.ReadByte();
for (int i = 0; i < 8; i++)
{
//we unpack the bits
if ((input & (byte)Math.Pow(2, i)) != 0) //read 1 bit
{
output.SetPixel((x * 8) + i, y, Color.Black);
}
else //read 0 bit
{
output.SetPixel((x * 8) + i, y, Color.White);
}
}
}
}
}
return output;
}
示例8: Stroke
public Stroke(Bitmap bitmap,Color color,float a,float b,float c,float soft,bool flat,bool square)
{
//Create shape
shape=(Bitmap)bitmap.Clone();
for(int i=0;i<shape.Width;i++)
{
for(int j=0;j<shape.Height;j++)
{
float x=(float)(i-shape.Width/2);
float y=(float)(j-shape.Height/2);
float len2=x*x+y*y;
float r=Math.Min(shape.Width/2,shape.Height/2);
float r2=r*r;
if(square||len2<=r2)
{
Color col=shape.GetPixel(i,j);
float ii=(((float)(col.R+col.G+col.B))/3f)/255f;
int aa=(int)(((a*ii*ii+b*ii+c)*(((float)color.A)/255f)*255f));
if(aa<0)
aa=0;
if(aa>255)
aa=255;
float sa=1f;
if(soft>0f)
{
sa=1f-(len2/r2)*soft;
if(sa<0f)
sa=0f;
if(sa>1f)
sa=1f;
}
if(flat)
shape.SetPixel(i,j,Color.FromArgb((int)(((float)aa)*sa),color));
else
{
Color cc=shape.GetPixel(i,j);
int rr=(int)((((float)cc.R)/255f)*(((float)color.R)/255f)*255f);
if(rr<0)
rr=0;
if(rr>255)
rr=255;
int gg=(int)((((float)cc.G)/255f)*(((float)color.G)/255f)*255f);
if(gg<0)
gg=0;
if(gg>255)
gg=255;
int bb=(int)((((float)cc.B)/255f)*(((float)color.B)/255f)*255f);
if(bb<0)
bb=0;
if(bb>255)
bb=255;
shape.SetPixel(i,j,Color.FromArgb((int)(((float)aa)*sa),rr,gg,bb));
}
}
else
shape.SetPixel(i,j,Color.FromArgb(0,0,0,0));
}
}
}
示例9: MakeImage
private void MakeImage( short[] colors )
{
Image = new System.Drawing.Bitmap( 34, 14 );
if ( colors == null )
{
this.NoHue = true;
return;
}
// Draw border
for ( int x = 0; x < 34; x++ )
{
Image.SetPixel( x, 0, Color.Black );
Image.SetPixel( x, 13, Color.Black );
}
for ( int y = 1; y < 14; y++ )
{
Image.SetPixel( 0, y, Color.Black );
Image.SetPixel( 33, y, Color.Black );
}
for ( int i = 0; i < 32; i++ )
{
for ( int y = 1; y < 13; y++ )
Image.SetPixel( i + 1, y, TheBox.Mul.Hue.ToColor( colors[i] ) );
}
}
示例10: GetMandelbrotImage
static Bitmap GetMandelbrotImage(PictureBox pictureBox, double maxr, double minr, double maxi, double mini)
{
currentMaxR = maxr;
currentMaxI = maxi;
currentMinR = minr;
currentMinI = mini;
var img = new Bitmap(pictureBox.Width, pictureBox.Height);
double xjump = (maxr - minr)/Convert.ToDouble(img.Width);
double yjump = (maxi - mini)/Convert.ToDouble(img.Height);
int loopmax = 1000; // the 'resolution'.. lower means faster..
for (int x = 0; x < img.Width; x++)
{
double cx = (xjump*x) - Math.Abs(minr);
for (int y = 0; y < img.Height; y++)
{
double zx = 0;
double zy = 0;
var cy = (yjump*y) - Math.Abs(mini);
var loopgo = 0;
while (zx*zx + zy*zy <= 4 && loopgo < loopmax)
{
loopgo++;
var tempzx = zx;
zx = (zx*zx) - (zy*zy) + cx;
zy = (2*tempzx*zy) + cy;
}
if (loopgo != loopmax)
img.SetPixel(x, y, Color.FromArgb(loopgo % 128 * 2, loopgo % 32 * 7, loopgo % 16 * 14));
else
img.SetPixel(x, y, Color.Black);
}
}
return img;
}
示例11: ConvertBytesToImage
/// <summary>
/// Converts byte buffer to Image with given bitmap type
/// </summary>
/// <param name="data"></param>
/// <param name="w"></param>
/// <param name="h"></param>
/// <param name="type"></param>
/// <returns></returns>
public static Image ConvertBytesToImage(byte[] data, int w, int h, ImageType type = ImageType.RGB) {
var bitmap = new Bitmap(w,h);
var channels = GetChannelCount(type);
var bluefirst = type == ImageType.BGR || type == ImageType.BGRA;
var size = w * h * channels;
if (data.Length < size) {
throw new Exception("invalid buffer size");
}
var i = -1;
for (var r = 0; r < h; r++) {
for (var c = 0; c < w; c++) {
if (channels == 1) {
int gray = data[++i];
bitmap.SetPixel(c, r, Color.FromArgb(gray, gray, gray));
}
else {
var buf = new[] {data[++i], data[++i], data[++i], channels == 4 ? data[++i] : (byte)0};
var basecolor = Color.FromArgb(bluefirst?buf[2]:buf[0],buf[1],bluefirst?buf[0]:buf[2]);
if (channels == 4) {
bitmap.SetPixel(c, r, Color.FromArgb(buf[3], basecolor));
}
else {
bitmap.SetPixel(c,r,basecolor);
}
}
}
}
return bitmap;
}
示例12: GetBitmapsSimilarityRatio
public double GetBitmapsSimilarityRatio(Bitmap first, Bitmap second)
{
int DiferentPixels = 0;
Bitmap container = new Bitmap(first.Width, first.Height);
for (int i = 0; i < first.Width; i++)
{
for (int j = 0; j < first.Height; j++)
{
int r1 = second.GetPixel(i, j).R;
int g1 = second.GetPixel(i, j).G;
int b1 = second.GetPixel(i, j).B;
int r2 = first.GetPixel(i, j).R;
int g2 = first.GetPixel(i, j).G;
int b2 = first.GetPixel(i, j).B;
if (r1 != r2 && g1 != g2 && b1 != b2)
{
DiferentPixels++;
container.SetPixel(i, j, Color.Red);
}
else
container.SetPixel(i, j, first.GetPixel(i, j));
}
}
int TotalPixels = first.Width * first.Height;
float dierence = (float)((float)DiferentPixels / (float)TotalPixels);
float percentage = dierence * 100;
return percentage;
}
示例13: CreateBitmapFromMap
public static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
int pallete = gradientmapLd.Height;
Bitmap bmp = new Bitmap(map.Width, map.Height);
Color[] colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{
colours[i] = gradientmapLd.GetPixel(0, i);
}
for (int y = 0; y < map.Height; y++)
{
for (int x = 0; x < map.Width; x++)
{
// 512 is the largest possible height before colours clamp
int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
// Handle error conditions
if (colorindex > pallete - 1 || colorindex < 0)
bmp.SetPixel(x, map.Height - y - 1, Color.Red);
else
bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
}
}
return bmp;
}
示例14: Compare
public static int Compare(Bitmap processedImage, Bitmap originalImage, out Bitmap diffImage)
{
var width = processedImage.Width;
var height = processedImage.Height;
diffImage = new Bitmap(width, height);
var diffCount = 0;
var eqColor = Color.White;
var neColor = Color.Red;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
if (processedImage.GetPixel(x, y).Equals(originalImage.GetPixel(x, y)))
diffImage.SetPixel(x, y, eqColor);
else
{
diffImage.SetPixel(x, y, neColor);
diffCount++;
}
}
}
return diffCount;
}
示例15: GenerateBackgroundTest
public void GenerateBackgroundTest()
{
Bitmap backgroundTemplate = new Bitmap(30, 20);
backgroundTemplate.SetPixel(0, 0, Color.Red);
backgroundTemplate.SetPixel(19, 9, Color.Blue);
const int width = 50;
const int height = 50;
Bitmap actual = StereoPictureBuilder_Accessor.GenerateBackground(backgroundTemplate, width, height);
Bitmap expected = new Bitmap(width, height);
expected.SetPixel(0, 0, Color.Red);
expected.SetPixel(30, 0, Color.Red);
expected.SetPixel(0, 20, Color.Red);
expected.SetPixel(30, 20, Color.Red);
expected.SetPixel(19, 9, Color.Blue);
expected.SetPixel(49, 9, Color.Blue);
expected.SetPixel(19, 29, Color.Blue);
expected.SetPixel(49, 29, Color.Blue);
expected.SetPixel(19, 49, Color.Blue);
expected.SetPixel(49, 49, Color.Blue);
//Assert.AreEqual(expected, actual);
Assert.AreEqual(expected.Width, actual.Width);
Assert.AreEqual(expected.Height, actual.Height);
Assert.AreEqual(expected.GetPixel(0, 0), actual.GetPixel(0, 0));
Assert.AreEqual(expected.GetPixel(49, 49), actual.GetPixel(49, 49));
}