本文整理汇总了C#中MatterHackers.Agg.Image.ImageBuffer.GetBufferOffsetXY方法的典型用法代码示例。如果您正苦于以下问题:C# ImageBuffer.GetBufferOffsetXY方法的具体用法?C# ImageBuffer.GetBufferOffsetXY怎么用?C# ImageBuffer.GetBufferOffsetXY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatterHackers.Agg.Image.ImageBuffer
的用法示例。
在下文中一共展示了ImageBuffer.GetBufferOffsetXY方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoDilate3x3MaxValue
public static void DoDilate3x3MaxValue(ImageBuffer source, ImageBuffer dest)
{
if (source.BitDepth != 32 || dest.BitDepth != 32)
{
throw new NotImplementedException("We only work with 32 bit at the moment.");
}
if (source.Width != dest.Width || source.Height != dest.Height)
{
throw new NotImplementedException("Source and Dest have to be the same size");
}
int height = source.Height;
int width = source.Width;
int sourceStrideInBytes = source.StrideInBytes();
int destStrideInBytes = dest.StrideInBytes();
byte[] sourceBuffer = source.GetBuffer();
byte[] destBuffer = dest.GetBuffer();
for (int testY = 1; testY < height - 1; testY++)
{
for (int testX = 1; testX < width - 1; testX++)
{
RGBA_Bytes maxColor = RGBA_Bytes.Black;
int sourceOffset = source.GetBufferOffsetXY(testX, testY - 1);
// x-1, y-1
//maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset - 4);
// x0, y-1
maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 0);
// x1, y-1
//maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 4);
// x-1, y0
maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes - 4);
// x0, y0
maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 0);
// x+1, y0
maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 4);
// x-1, y+1
//maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 - 4);
// x0, y+1
maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 0);
// x+1, y+1
//maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 4);
int destOffset = dest.GetBufferOffsetXY(testX, testY);
destBuffer[destOffset + 2] = maxColor.red;
destBuffer[destOffset + 1] = maxColor.green;
destBuffer[destOffset + 0] = maxColor.blue;
destBuffer[destOffset + 3] = 255;
}
}
}
示例2: DoDilate3x3Binary
public static void DoDilate3x3Binary(ImageBuffer source, ImageBuffer dest, int threshold)
{
if (source.BitDepth != 32 || dest.BitDepth != 32)
{
throw new NotImplementedException("We only work with 32 bit at the moment.");
}
if (source.Width != dest.Width || source.Height != dest.Height)
{
throw new NotImplementedException("Source and Dest have to be the same size");
}
int height = source.Height;
int width = source.Width;
int sourceStrideInBytes = source.StrideInBytes();
int destStrideInBytes = dest.StrideInBytes();
byte[] sourceBuffer = source.GetBuffer();
byte[] destBuffer = dest.GetBuffer();
for (int testY = 1; testY < height-1; testY++)
{
for (int testX = 1; testX < width - 1; testX++)
{
for (int sourceY = -1; sourceY <= 1; sourceY++)
{
for (int sourceX = -1; sourceX <= 1; sourceX++)
{
int sourceOffset = source.GetBufferOffsetXY(testX + sourceX, testY + sourceY);
if (sourceBuffer[sourceOffset] > threshold)
{
int destOffset = dest.GetBufferOffsetXY(testX, testY);
destBuffer[destOffset++] = 255;
destBuffer[destOffset++] = 255;
destBuffer[destOffset++] = 255;
destBuffer[destOffset++] = 255;
}
}
}
}
}
}
示例3: ConvertBitmapToImage
private static bool ConvertBitmapToImage(ImageBuffer destImage, Bitmap m_WidowsBitmap)
{
if (m_WidowsBitmap != null)
{
switch (m_WidowsBitmap.PixelFormat)
{
case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
{
destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);
if (destImage.GetRecieveBlender() == null)
{
destImage.SetRecieveBlender(new BlenderBGRA());
}
BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
int sourceIndex = 0;
int destIndex = 0;
unsafe
{
int offset;
byte[] destBuffer = destImage.GetBuffer(out offset);
byte* pSourceBuffer = (byte*)bitmapData.Scan0;
for (int y = 0; y < destImage.Height; y++)
{
destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
for (int x = 0; x < destImage.Width; x++)
{
#if true
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
#else
RGBA_Bytes notPreMultiplied = new RGBA_Bytes(pSourceBuffer[sourceIndex + 0], pSourceBuffer[sourceIndex + 1], pSourceBuffer[sourceIndex + 2], pSourceBuffer[sourceIndex + 3]);
sourceIndex += 4;
RGBA_Bytes preMultiplied = notPreMultiplied.GetAsRGBA_Floats().premultiply().GetAsRGBA_Bytes();
destBuffer[destIndex++] = preMultiplied.blue;
destBuffer[destIndex++] = preMultiplied.green;
destBuffer[destIndex++] = preMultiplied.red;
destBuffer[destIndex++] = preMultiplied.alpha;
#endif
}
}
}
m_WidowsBitmap.UnlockBits(bitmapData);
return true;
}
case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
{
destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);
BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
int sourceIndex = 0;
int destIndex = 0;
unsafe
{
int offset;
byte[] destBuffer = destImage.GetBuffer(out offset);
byte* pSourceBuffer = (byte*)bitmapData.Scan0;
for (int y = 0; y < destImage.Height; y++)
{
sourceIndex = y * bitmapData.Stride;
destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
for (int x = 0; x < destImage.Width; x++)
{
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
destBuffer[destIndex++] = 255;
}
}
}
m_WidowsBitmap.UnlockBits(bitmapData);
return true;
}
case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
{
Copy8BitDataToImage(destImage, m_WidowsBitmap);
return true;
}
default:
throw new System.NotImplementedException();
}
}
return false;
}
示例4: ImageBuffer
public ImageBuffer(ImageBuffer sourceImage)
{
SetDimmensionAndFormat(sourceImage.Width, sourceImage.Height, sourceImage.StrideInBytes(), sourceImage.BitDepth, sourceImage.GetBytesBetweenPixelsInclusive(), true);
int offset = sourceImage.GetBufferOffsetXY(0, 0);
byte[] buffer = sourceImage.GetBuffer();
byte[] newBuffer = new byte[buffer.Length];
agg_basics.memcpy(newBuffer, offset, buffer, offset, buffer.Length - offset);
SetBuffer(newBuffer, offset);
SetRecieveBlender(sourceImage.GetRecieveBlender());
}
示例5: Fill
public void Fill(ImageBuffer bufferToFillOn, int x, int y)
{
unchecked // this way we can overflow the uint on negative and get a big number
{
if ((uint)x > bufferToFillOn.Width || (uint)y > bufferToFillOn.Height)
{
return;
}
}
destImage = bufferToFillOn;
imageStride = destImage.StrideInBytes();
destBuffer = destImage.GetBuffer();
int imageWidth = destImage.Width;
int imageHeight = destImage.Height;
pixelsChecked = new bool[destImage.Width * destImage.Height];
int startColorBufferOffset = destImage.GetBufferOffsetXY(x, y);
fillRule.SetStartColor(new RGBA_Bytes(destImage.GetBuffer()[startColorBufferOffset + 2], destImage.GetBuffer()[startColorBufferOffset + 1], destImage.GetBuffer()[startColorBufferOffset]));
LinearFill(x, y);
while (ranges.Count > 0)
{
Range range = ranges.Dequeue();
int downY = range.y - 1;
int upY = range.y + 1;
int downPixelOffset = (imageWidth * (range.y - 1)) + range.startX;
int upPixelOffset = (imageWidth * (range.y + 1)) + range.startX;
for (int rangeX = range.startX; rangeX <= range.endX; rangeX++)
{
if (range.y > 0)
{
if (!pixelsChecked[downPixelOffset])
{
int bufferOffset = destImage.GetBufferOffsetXY(rangeX, downY);
if (fillRule.CheckPixel(destBuffer, bufferOffset))
{
LinearFill(rangeX, downY);
}
}
}
if (range.y < (imageHeight - 1))
{
if (!pixelsChecked[upPixelOffset])
{
int bufferOffset = destImage.GetBufferOffsetXY(rangeX, upY);
if (fillRule.CheckPixel(destBuffer, bufferOffset))
{
LinearFill(rangeX, upY);
}
}
}
upPixelOffset++;
downPixelOffset++;
}
}
}
示例6: DoErode3x3MinValue
public static void DoErode3x3MinValue(ImageBuffer source, ImageBuffer dest)
{
if (source.BitDepth != 32 || dest.BitDepth != 32)
{
throw new NotImplementedException("We only work with 32 bit at the moment.");
}
if (source.Width != dest.Width || source.Height != dest.Height)
{
throw new NotImplementedException("Source and Dest have to be the same size");
}
int height = source.Height;
int width = source.Width;
int sourceStrideInBytes = source.StrideInBytes();
int destStrideInBytes = dest.StrideInBytes();
byte[] sourceBuffer = source.GetBuffer();
byte[] destBuffer = dest.GetBuffer();
// This can be made much faster by holding the buffer pointer and offsets better // LBB 2013 06 09
for (int testY = 1; testY < height - 1; testY++)
{
for (int testX = 1; testX < width - 1; testX++)
{
RGBA_Bytes minColor = RGBA_Bytes.White;
int sourceOffset = source.GetBufferOffsetXY(testX, testY - 1);
// x-1, y-1
//minColor = MinColor(sourceBuffer, minColor, sourceOffset - 4);
// x0, y-1
minColor = MinColor(sourceBuffer, minColor, sourceOffset + 0);
// x1, y-1
//minColor = MinColor(sourceBuffer, minColor, sourceOffset + 4);
// x-1, y0
minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes - 4);
// x0, y0
minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 0);
// x+1, y0
minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 4);
// x-1, y+1
//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 - 4);
// x0, y+1
minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 0);
// x+1, y+1
//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 4);
int destOffset = dest.GetBufferOffsetXY(testX, testY);
destBuffer[destOffset + 2] = minColor.red;
destBuffer[destOffset + 1] = minColor.green;
destBuffer[destOffset + 0] = minColor.blue;
destBuffer[destOffset + 3] = 255;
}
}
}