本文整理汇总了C#中FastBitmap类的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap类的具体用法?C# FastBitmap怎么用?C# FastBitmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastBitmap类属于命名空间,在下文中一共展示了FastBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyFilter
/// <summary>
/// Applies the filter to the specified <paramref name="bitmap"/>. This method
/// first calls <see cref="ImageReplacementFilter.GetDestinationDimensions(FastBitmap, out Int32, out Int32)" />
/// to calculate the size of the destination image. Then it calls
/// <see cref="ImageReplacementFilter.ApplyFilter(FastBitmap, FastBitmap, Graphics)" />
/// which is where the overridden class implements its filter algorithm.
/// </summary>
/// <param name="bitmap">
/// Image to apply the <see cref="ImageReplacementFilter" /> to.
/// </param>
public override sealed void ApplyFilter(FastBitmap bitmap)
{
OnBeginApplyFilter(bitmap);
// get destination dimensions
int width, height;
bool shouldContinue = GetDestinationDimensions(bitmap, out width, out height);
if (!shouldContinue)
return;
DrawingVisual dv = new DrawingVisual();
ConfigureDrawingVisual(bitmap, dv);
DrawingContext dc = dv.RenderOpen();
ApplyFilter(bitmap, dc, width, height);
dc.Close();
RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(width, height);
rtb.Render(dv);
FastBitmap destination = new FastBitmap(rtb);
// copy metadata
// TODO
/*foreach (PropertyItem propertyItem in bitmap.InnerBitmap.PropertyItems)
destination.InnerBitmap.SetPropertyItem(propertyItem);*/
// set new image
bitmap.InnerBitmap = destination.InnerBitmap;
OnEndApplyFilter();
}
示例2: PixelReader
public PixelReader(FastBitmap fastBitmap, Rectangle region)
{
if (fastBitmap == null)
throw new ArgumentOutOfRangeException("fastBitmap", "must not be null");
_fastBitmap = fastBitmap;
_region = region;
}
示例3: DrawPoint
/// <summary>
/// Draw an one-pixel point of fixed color (defined by <see cref="PixelData"/>) in fixed position.
/// </summary>
public static void DrawPoint(FastBitmap bmp, int x, int y, PixelData color)
{
PixelData* addr = bmp[x, y];
addr->R = color.R;
addr->G = color.G;
addr->B = color.B;
}
示例4: RenderFrame
private Bitmap RenderFrame(LinePairCollection lines, FastBitmap startImage, FastBitmap endImage, double percent)
{
var forwardsAndBackwards = InterpolateLines(lines, percent);
using (Bitmap forward = ComputePreimage( startImage, forwardsAndBackwards.Item1))
using (Bitmap backward = ComputePreimage( endImage, forwardsAndBackwards.Item2))
return BlendImages(forward, backward, 1 - percent);
}
示例5: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
return new BrightnessAdjustmentEffect
{
Level = this.Level/100.0
};
}
示例6: CropArea
public static unsafe Bitmap CropArea(Bitmap original, int posX, int posY, int width, int height)
{
Bitmap ret = new Bitmap(width, height);
#if false
FastBitmap retFast = new FastBitmap(ret);
FastBitmap origFast = new FastBitmap(original);
retFast.LockImage();
origFast.LockImage();
for (int x = posX; x < posX + width && x < original.Width; ++x)
{
for (int y = posY; y < posY + height && y < original.Height; ++y)
{
retFast.CopyFrom(x - posX, y - posY, origFast.GetPixelData(x, y));
}
}
retFast.UnlockImage();
origFast.UnlockImage();
#else
using (Graphics g = Graphics.FromImage(ret))
{
RectangleF source = new RectangleF(posX, posY, width, height);
RectangleF target = new RectangleF(0, 0, width, height);
g.DrawImage(original, target, source, GraphicsUnit.Pixel);
}
#endif
return ret;
}
示例7: CopyScaledPixels
static unsafe void CopyScaledPixels( FastBitmap src, FastBitmap dst, Size scale,
Rectangle srcRect, Rectangle dstRect, byte rgbScale)
{
int srcWidth = srcRect.Width, dstWidth = dstRect.Width;
int srcHeight = srcRect.Height, dstHeight = dstRect.Height;
int srcX = srcRect.X, dstX = dstRect.X;
int srcY = srcRect.Y, dstY = dstRect.Y;
int scaleWidth = scale.Width, scaleHeight = scale.Height;
for( int yy = 0; yy < dstHeight; yy++ ) {
int scaledY = yy * srcHeight / scaleHeight;
int* srcRow = src.GetRowPtr( srcY + scaledY );
int* dstRow = dst.GetRowPtr( dstY + yy );
for( int xx = 0; xx < dstWidth; xx++ ) {
int scaledX = xx * srcWidth / scaleWidth;
int pixel = srcRow[srcX + scaledX];
int col = pixel & ~0xFFFFFF; // keep a but clear rgb
col |= ((pixel & 0xFF) * rgbScale / 255);
col |= (((pixel >> 8) & 0xFF) * rgbScale / 255) << 8;
col |= (((pixel >> 16) & 0xFF) * rgbScale / 255) << 16;
dstRow[dstX + xx] = col;
}
}
}
示例8: FindPupil
public Rectangle FindPupil(FastBitmap bitmap, Rectangle eye, double[,] angulars)
{
cube = new double[eye.Width, eye.Height, maxRad - minRad];
double maxCubeval = 0;
int maxi = 0, maxj = 0, maxr = 0;
Parallel.For(0, eye.Width - (int)(0.5 * eye.Width), i =>
//for (int i = 0; i < eye.Width; i++)
{
for (int j = 0; j < eye.Height - 0.5 * eye.Height; j++)
{
for (int r = 0; r < maxRad - minRad; r++)
{
cube[i, j, r] = CountCubeValue(i, j, bitmap, eye, angulars);
if (maxCubeval <= cube[i, j, r])
{
maxi = i;
maxj = j;
maxr = r;
maxCubeval = cube[i, j, r];
}
}
}
});
Rectangle result = new Rectangle(eye.X + maxi, eye.Y + maxj, minRad + maxr, minRad + maxr);
return result;
}
示例9: DrawGraph
public FastBitmap DrawGraph(string StatName, double MaxVal)
{
Bitmap bitmap = new Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
FastBitmap bmp = new FastBitmap(bitmap);
bmp.LockBitmap();
ProfilerValueManager statManager = GetStat(StatName);
double ScaleFactor = 1 / (MaxVal / 200); //We multiply by this so that the graph uses the full space
double[] Stats = statManager.GetInfos();
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, Stats, ScaleFactor))
bmp.SetPixel(x, 200 - y, BarColor);
else
{
//Check whether the line needs drawn
if (DrawLine(y, ScaleFactor))
bmp.SetPixel(x, 200 - y, LineColor);
else
bmp.SetPixel(x, 200 - y, BackgroundColor);
}
}
}
bmp.UnlockBitmap();
return bmp;
}
示例10: ImagePreview
public ImagePreview(String path)
{
InitializeComponent();
this.path = path;
StreamReader reader = new StreamReader(path);
Bitmap bmpTemp = (Bitmap)Bitmap.FromStream(reader.BaseStream);
Bitmap bmpTemp2 = new Bitmap(bmpTemp.Size.Width, bmpTemp.Size.Height);
bmpTemp2.SetResolution(bmpTemp.HorizontalResolution, bmpTemp.VerticalResolution);
Graphics gr = Graphics.FromImage(bmpTemp2);
gr.DrawImage(bmpTemp, new Point());
bmpTemp.Dispose();
reader.Close();
bmp = new FastBitmap(bmpTemp2);
bmp.Bitmap.SetResolution(96, 96);
Text = path;
ClientSize = bmp.Size;
graphicsPanel.Left = 0;
graphicsPanel.Top = 0;
graphicsPanel.Size = bmp.Size;
graphics = this.graphicsPanel.CreateGraphics();
}
示例11: 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);
}
示例12: FastBitmap
public FastBitmap(FastBitmap bmp, Rectangle src)
{
if (bmp == null)
throw new ArgumentNullException("bitmap");
bitmap = new Bitmap(src.Width, src.Height, PixelFormat.Format8bppIndexed);
bitmap.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
levels = bmp.Levels;
bitmap.Palette = bmp.Palette;
Lock();
unsafe
{
if (bmp != null)
{
Byte* pPixel = (Byte*)bitmapData.Scan0;
for (int y = 0; y < bitmap.Height; y++)
{
for (int x = 0; x < bitmap.Width; x++)
{
pPixel[x] = bmp[x + src.X, y + src.Y];
}
pPixel += bitmapData.Stride;
}
}
}
}
示例13: 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);
}
}
}
示例14: GetImageWithDisplacement
public ReturnImage GetImageWithDisplacement(FastBitmap currFrame, FastBitmap nextFrame, List<Point> edgePoints)
{
_nBytesPerPixel = currFrame.CCount;
currFrame.LockBits();
nextFrame.LockBits();
byte[] currRgbValues = currFrame.Pixels;
byte[] nextRgbValues = nextFrame.Pixels;
ConcurrentDictionary<Point, Point> displacements = new ConcurrentDictionary<Point, Point>();
Parallel.ForEach(edgePoints, (edgePoint) =>
{
int edgePointPos;
List<Color> pointVicinity = GetPointVicinity(edgePoint, currRgbValues, currFrame.Width, currFrame.Height, currFrame.Stride, out edgePointPos);
_brief = new BRIEF((POINT_WINDOW_SIDE + 1) * (POINT_WINDOW_SIDE + 1), edgePointPos);
string vicinityDescriptor = _brief.GetImageDescriptor(pointVicinity);
if (pointVicinity[edgePointPos] != Color.Black)
{
Point nextFramePoint = FindPointDiscplacement(edgePoint, nextRgbValues, nextFrame.Width, nextFrame.Height, vicinityDescriptor, nextFrame.Stride, pointVicinity[edgePointPos]);
displacements.TryAdd(edgePoint, nextFramePoint);
}
else
displacements.TryAdd(edgePoint, edgePoint);
});
currFrame.UnlockBits();
nextFrame.UnlockBits();
Frame frame = GetFrameByChanell(currFrame, displacements);
//frames.Add();
ReturnImage image = new ReturnImage(frame, currFrame);
return image;
}
示例15: Draw
public override void Draw( IWindowInfo info, Bitmap framebuffer )
{
using( FastBitmap bmp = new FastBitmap( framebuffer, true ) ) {
IntPtr scan0 = bmp.Scan0;
int size = bmp.Width * bmp.Height * 4;
IntPtr colorSpace = OSX.API.CGColorSpaceCreateDeviceRGB();
IntPtr provider = OSX.API.CGDataProviderCreateWithData( IntPtr.Zero, scan0, size, IntPtr.Zero );
const uint flags = 4 | (2 << 12);
IntPtr image = OSX.API.CGImageCreate( bmp.Width, bmp.Height, 8, 8 * 4, bmp.Stride,
colorSpace, flags, provider, IntPtr.Zero, 0, 0 );
IntPtr context = IntPtr.Zero;
OSStatus err = OSX.API.QDBeginCGContext( windowPort, ref context );
OSX.API.CheckReturn( err );
OSX.HIRect rect = new OSX.HIRect();
rect.Origin.X = 0; rect.Origin.Y = 0;
rect.Size.X = bmp.Width; rect.Size.Y = bmp.Height;
OSX.API.CGContextDrawImage( context, rect, image );
OSX.API.CGContextSynchronize( context );
err = OSX.API.QDEndCGContext( windowPort, ref context );
OSX.API.CheckReturn( err );
OSX.API.CGImageRelease( image );
OSX.API.CGDataProviderRelease( provider );
OSX.API.CGColorSpaceRelease( colorSpace );
}
}