本文整理汇总了C#中FastBitmap.SetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap.SetPixel方法的具体用法?C# FastBitmap.SetPixel怎么用?C# FastBitmap.SetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FastBitmap
的用法示例。
在下文中一共展示了FastBitmap.SetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyArea
public IBitmap ApplyArea(IArea area)
{
//todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
//This will require to change the rendering as well to offset the location
byte zero = (byte)0;
Bitmap output = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (FastBitmap inBmp = new FastBitmap (_bitmap, ImageLockMode.ReadOnly))
{
using (FastBitmap outBmp = new FastBitmap (output, ImageLockMode.WriteOnly, true))
{
for (int y = 0; y < Height; y++)
{
int bitmapY = Height - y - 1;
for (int x = 0; x < Width; x++)
{
System.Drawing.Color color = inBmp.GetPixel(x, bitmapY);
byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
outBmp.SetPixel(x, bitmapY, System.Drawing.Color.FromArgb(alpha, color));
}
}
}
}
return new DesktopBitmap(output, _graphics);
}
示例2: ApplyFilter
public void ApplyFilter(FastBitmap image)
{
const int blurRadius = 5;
var map = new List<Color>[image.Width, image.Height];
for (var i = 0; i < image.Width; ++i)
{
for (var j = 0; j < image.Height; ++j)
{
for (var iInner = -blurRadius; iInner < blurRadius; ++iInner)
{
var x = i + iInner;
if (x < 0)
{
continue;
}
if (x >= image.Width)
{
break;
}
for (var jInner = -blurRadius; jInner < blurRadius; ++jInner)
{
var y = j + jInner;
if (y < 0)
{
continue;
}
if (y >= image.Height)
{
break;
}
var distance = Math.Sqrt((iInner*iInner) + (jInner*jInner));
if (distance > blurRadius)
{
continue;
}
if (map[i, j] == null)
{
map[i, j] = new List<Color>();
}
map[i, j].Add(image.GetPixel(x, y));
}
}
}
}
for (var i = 0; i < image.Width; ++i)
{
for (var j = 0; j < image.Height; ++j)
{
var r = (int)map[i, j].Average(a => a.R);
var g = (int)map[i, j].Average(a => a.G);
var b = (int)map[i, j].Average(a => a.B);
image.SetPixel(i, j, r, g, b);
}
}
}
示例3: FastBitmapModificationsAreApplied
public void FastBitmapModificationsAreApplied()
{
List<string> files = new List<string>
{
ImageSources.GetFilePathByName("format-Penguins.jpg"),
ImageSources.GetFilePathByName("format-Penguins.png"),
};
foreach (string file in files)
{
Bitmap bmp = new Bitmap(file);
Bitmap original = (Bitmap)bmp.Clone();
using (FastBitmap fbmp = new FastBitmap(bmp))
{
// draw a pink diagonal line
for (int i = 0; i < 10; i++)
{
fbmp.SetPixel(i, i, Color.Pink);
}
}
AssertionHelpers.AssertImagesAreDifferent(original, bmp, "because modifying the fast bitmap should have modified the original bitmap");
}
}
示例4: fastBitmapEqualOriginBitmap
public void fastBitmapEqualOriginBitmap()
{
Bitmap img = new Bitmap("../../image/1.jpg");
FastBitmap fastBitmap = new FastBitmap(img);
fastBitmap.SetPixel(0, 0, Color.Red);
Assert.AreEqual(img, fastBitmap.ToBitmap());
Assert.IsTrue(img.GetPixel(0, 0) == Color.FromArgb(255,255,0,0));
}
示例5: DrawGraph
public FastBitmap DrawGraph(string StatName)
{
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double MaxVal = statManager.GetMaxValue();
double ScaleFactor = 1 / (MaxVal / 200); //We multiply by this so that the graph uses the full space
ProfilerValueInfo[] Stats = new ProfilerValueInfo[10];
int i = 0;
foreach (ProfilerValueInfo info in statManager.GetInfos())
{
Stats[i] = info;
i++;
}
for (i = 0; i < Stats.Length; i++)
{
//Update the scales
Stats[i].Value = Stats[i].Value * ScaleFactor;
}
for (int x = 200; x > 0; x--)
{
for (int y = 200; y > 0; y--)
{
//Note: we do 200-x and 200-y to flip the graph on the X and Y axises
if (IsInGraphBar(x, y, Stats))
bmp.SetPixel(200 - x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
if (DrawLine(y, ScaleFactor))
bmp.SetPixel(200 - x, 200 - y, LineColor);
else
bmp.SetPixel(200 - x, 200 - y, BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例6: ProcessImage
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
/// the image to process.
/// </param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public Image ProcessImage(ImageFactory factory)
{
Bitmap newImage = null;
Image image = factory.Image;
try
{
Tuple<int, bool> parameters = this.DynamicParameter;
int degrees = parameters.Item1;
bool rotate = parameters.Item2;
int width = image.Width;
int height = image.Height;
newImage = new Bitmap(image);
using (FastBitmap fastBitmap = new FastBitmap(newImage))
{
if (!rotate)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
HslaColor original = HslaColor.FromColor(fastBitmap.GetPixel(x, y));
HslaColor altered = HslaColor.FromHslaColor(degrees / 360f, original.S, original.L, original.A);
fastBitmap.SetPixel(x, y, altered);
}
}
}
else
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
HslaColor original = HslaColor.FromColor(fastBitmap.GetPixel(x, y));
HslaColor altered = HslaColor.FromHslaColor((original.H + (degrees / 360f)) % 1, original.S, original.L, original.A);
fastBitmap.SetPixel(x, y, altered);
}
}
}
}
image.Dispose();
image = newImage;
}
catch (Exception ex)
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;
}
示例7: GenerateBitmap
private static int GenerateBitmap(FastBitmap bmp, byte[] buf, List<Color> fourColors)
{
int w = bmp.Width;
int h = bmp.Height;
int nibbleOffset = 0;
var nibble_end = buf.Length * 2;
var x = 0;
var y = 0;
for (; ; )
{
if (nibbleOffset >= nibble_end)
return -1;
var v = GetNibble(buf, nibbleOffset++);
if (v < 0x4)
{
v = (v << 4) | GetNibble(buf, nibbleOffset++);
if (v < 0x10)
{
v = (v << 4) | GetNibble(buf, nibbleOffset++);
if (v < 0x040)
{
v = (v << 4) | GetNibble(buf, nibbleOffset++);
if (v < 4)
{
v |= (w - x) << 2;
}
}
}
}
var len = v >> 2;
if (len > (w - x))
len = (w - x);
var color = v & 0x03;
if (color > 0)
{
Color c = fourColors[color];
bmp.SetPixel(x, y, c, len);
}
x += len;
if (x >= w)
{
y++;
if (y >= h)
break;
x = 0;
nibbleOffset += (nibbleOffset & 1);
}
}
return 0;
}
示例8: fastBitmapWriteTest
public void fastBitmapWriteTest()
{
FastBitmap img = new FastBitmap("../../image/1.jpg");
for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++)
{
img.SetPixel(x, y, Color.Red);
}
}
Assert.IsTrue(img.GetPixel(0, 0).R == 255);
Assert.IsTrue(img.GetPixel(0, 0).G == 0);
Assert.IsTrue(img.GetPixel(0, 0).B == 0);
}
示例9: Grayscale
public static Bitmap Grayscale(Bitmap b)
{
FastBitmap fb = new FastBitmap(b);
for (int y = 0; y < b.Height; y++)
{
for (int x = 0; x < b.Width; x++)
{
Color c = fb.GetPixel(x, y);
int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
fb.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
}
}
return fb.GetBitmap();
}
示例10: ToGrayscale
public FastBitmap ToGrayscale()
{
FastBitmap bitmap = new FastBitmap(new Bitmap(map.GetLength(0), map.GetLength(1)));
for (int y = 0; y < bitmap.Height; y++)
{
for (int x = 0; x < bitmap.Width; x++)
{
int gray = (int)(255 * map[x, y] / (double)buckets);
bitmap.SetPixel(x, y, Color.FromArgb(gray, gray, gray).ToArgb());
}
}
return bitmap;
}
示例11: FastBitmapModificationsAreApplied
public void FastBitmapModificationsAreApplied(string file)
{
Bitmap bmp = new Bitmap(file);
Bitmap original = (Bitmap)bmp.Clone();
using (FastBitmap fbmp = new FastBitmap(bmp))
{
// draw a pink diagonal line
for (int i = 0; i < 10; i++)
{
fbmp.SetPixel(i, i, Color.Pink);
}
}
AssertionHelpers.AssertImagesAreDifferent(original, bmp, "because modifying the fast bitmap should have modified the original bitmap");
}
示例12: CopyTo
public void CopyTo(FastBitmap bitmap, Int32 destx, Int32 desty, Int32 srcx, Int32 srcy,
Int32 width, Int32 height)
{
try {
Lock();
bitmap.Lock();
for (Int32 y = 0; y < height; y++) {
for (Int32 x = 0; x < width; x++) {
Color c = GetPixel(srcx + x, srcy + y);
bitmap.SetPixel(destx + x, desty + y, c);
}
}
}
finally {
Unlock();
bitmap.Unlock();
}
}
示例13: Filter
public void Filter(FastBitmap bitmap, int radius)
{
Parallel.For (0, bitmap.Width, x=>
{
for (int y = 0; y < bitmap.Height; y++)
{
List<int> list = new List<int>();
for (int i = x - radius; i <= x + radius; i++)
{
for (int j = y - radius; j <= y + radius; j++)
{
if (i < 0 || j < 0 || i >= bitmap.Width || j >= bitmap.Height)
list.Add(Color.Black.ToArgb());
else
list.Add(bitmap.GetPixel(x, y).ToArgb());
}
}
list.Sort();
bitmap.SetPixel(x, y, Color.FromArgb(list[list.Count() / 2]));
}
}
);
}
示例14: DrawGraph
public FastBitmap DrawGraph(string StatName)
{
Bitmap bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double MaxVal = 0;
if (statManager != null)
MaxVal = statManager.GetMaxValue();
double ScaleFactor = 1/(MaxVal/200); //We multiply by this so that the graph uses the full space
double[] Stats2 = new double[0];
if (statManager != null)
Stats2 = statManager.GetInfos();
for (int i = 0; i < Stats2.Length; i++)
{
//Update the scales
Stats2[i] = Stats2[i]*ScaleFactor;
}
for (int x = 200; x > 0; x--)
{
for (int y = 200; y > 0; y--)
{
//Note: we do 200-y to flip the graph on the Y axis
if (IsInGraphBar(x, y, Stats2, ScaleFactor))
bmp.SetPixel(x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
bmp.SetPixel(x, 200 - y, DrawLine(y, ScaleFactor) ? LineColor : BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例15: ProcessImage
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">
/// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
/// the image to process.
/// </param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public Image ProcessImage(ImageFactory factory)
{
Bitmap newImage = null;
Image image = factory.Image;
try
{
Tuple<Color, Color, int> parameters = this.DynamicParameter;
Color original = parameters.Item1;
Color replacement = parameters.Item2;
byte originalR = original.R;
byte originalG = original.G;
byte originalB = original.B;
byte originalA = original.A;
byte replacementR = replacement.R;
byte replacementG = replacement.G;
byte replacementB = replacement.B;
byte replacementA = replacement.A;
int fuzziness = parameters.Item3;
byte minR = (originalR - fuzziness).ToByte();
byte minG = (originalG - fuzziness).ToByte();
byte minB = (originalB - fuzziness).ToByte();
byte maxR = (originalR + fuzziness).ToByte();
byte maxG = (originalG + fuzziness).ToByte();
byte maxB = (originalB + fuzziness).ToByte();
newImage = new Bitmap(image);
int width = image.Width;
int height = image.Height;
using (FastBitmap fastBitmap = new FastBitmap(newImage))
{
Parallel.For(
0,
height,
y =>
{
for (int x = 0; x < width; x++)
{
// Get the pixel color.
// ReSharper disable once AccessToDisposedClosure
Color currentColor = fastBitmap.GetPixel(x, y);
byte currentR = currentColor.R;
byte currentG = currentColor.G;
byte currentB = currentColor.B;
byte currentA = currentColor.A;
// Test whether it is in the expected range.
if (ImageMaths.InRange(currentR, minR, maxR))
{
if (ImageMaths.InRange(currentG, minG, maxG))
{
if (ImageMaths.InRange(currentB, minB, maxB))
{
// Ensure the values are within an acceptable byte range
// and set the new value.
byte r = (originalR + currentR - replacementR).ToByte();
byte g = (originalG + currentG - replacementG).ToByte();
byte b = (originalB + currentB - replacementB).ToByte();
// Allow replacement with transparent color.
byte a = currentA;
if (originalA != replacementA)
{
a = replacementA;
}
// ReSharper disable once AccessToDisposedClosure
fastBitmap.SetPixel(x, y, Color.FromArgb(a, r, g, b));
}
}
}
}
});
}
image.Dispose();
image = newImage;
}
catch (Exception ex)
{
if (newImage != null)
{
newImage.Dispose();
}
//.........这里部分代码省略.........