本文整理汇总了C#中MatterHackers.Agg.Image.ImageBuffer.GetRecieveBlender方法的典型用法代码示例。如果您正苦于以下问题:C# ImageBuffer.GetRecieveBlender方法的具体用法?C# ImageBuffer.GetRecieveBlender怎么用?C# ImageBuffer.GetRecieveBlender使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatterHackers.Agg.Image.ImageBuffer
的用法示例。
在下文中一共展示了ImageBuffer.GetRecieveBlender方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: LowLevelReadTGABitsFromBuffer
private static unsafe int LowLevelReadTGABitsFromBuffer(ImageBuffer imageToReadTo, byte[] wholeFileBuffer, int DestBitDepth)
{
STargaHeader TargaHeader = new STargaHeader();
int FileReadOffset;
if (!ReadTGAInfo(wholeFileBuffer, out TargaHeader))
{
return 0;
}
// if the frame we are loading is different then the one we have allocated
// or we don't have any bits allocated
if ((imageToReadTo.Width * imageToReadTo.Height) != (TargaHeader.Width * TargaHeader.Height))
{
imageToReadTo.Allocate(TargaHeader.Width, TargaHeader.Height, TargaHeader.Width * DestBitDepth / 8, DestBitDepth);
}
// work out the line width
switch (imageToReadTo.BitDepth)
{
case 24:
TGABytesPerLine = imageToReadTo.Width * 3;
if (imageToReadTo.GetRecieveBlender() == null)
{
imageToReadTo.SetRecieveBlender(new BlenderBGR());
}
break;
case 32:
TGABytesPerLine = imageToReadTo.Width * 4;
if (imageToReadTo.GetRecieveBlender() == null)
{
imageToReadTo.SetRecieveBlender(new BlenderBGRA());
}
break;
default:
throw new System.Exception("Bad bit depth.");
}
if (TGABytesPerLine > 0)
{
byte[] BufferToDecompressTo = null;
FileReadOffset = TargaHeaderSize + TargaHeader.PostHeaderSkip;
if (TargaHeader.ImageType == 10) // 10 is RLE compressed
{
BufferToDecompressTo = new byte[TGABytesPerLine * 2];
}
// read all the lines *
for (int i = 0; i < imageToReadTo.Height; i++)
{
byte[] BufferToCopyFrom;
int CopyOffset = 0;
int CurReadLine;
// bit 5 tells us if the image is stored top to bottom or bottom to top
if ((TargaHeader.Descriptor & 0x20) != 0)
{
// bottom to top
CurReadLine = imageToReadTo.Height - i - 1;
}
else
{
// top to bottom
CurReadLine = i;
}
if (TargaHeader.ImageType == 10) // 10 is RLE compressed
{
FileReadOffset = Decompress(BufferToDecompressTo, wholeFileBuffer, FileReadOffset, imageToReadTo.Width, TargaHeader.BPP, CurReadLine);
BufferToCopyFrom = BufferToDecompressTo;
}
else
{
BufferToCopyFrom = wholeFileBuffer;
CopyOffset = FileReadOffset;
}
int bufferOffset;
byte[] imageBuffer = imageToReadTo.GetBuffer(out bufferOffset);
switch (imageToReadTo.BitDepth)
{
case 8:
switch (TargaHeader.BPP)
{
case 24:
Do24To8Bit(imageBuffer, BufferToCopyFrom, CopyOffset, imageToReadTo.Width, CurReadLine);
break;
case 32:
Do32To8Bit(imageBuffer, BufferToCopyFrom, CopyOffset, imageToReadTo.Width, CurReadLine);
break;
}
break;
//.........这里部分代码省略.........
示例3: CreateScaledImage
public static ImageBuffer CreateScaledImage(ImageBuffer unscaledSourceImage, int width, int height)
{
ImageBuffer destImage = new ImageBuffer(width, height, 32, unscaledSourceImage.GetRecieveBlender());
// If the source image is more than twice as big as our dest image.
while (unscaledSourceImage.Width > destImage.Width * 2)
{
// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
// So we scale as many times as we need to get the Image to be the right size.
// If this were going to be a non-uniform scale we could do the x and y separately to get better results.
ImageBuffer halfImage = new ImageBuffer(unscaledSourceImage.Width / 2, unscaledSourceImage.Height / 2, 32, unscaledSourceImage.GetRecieveBlender());
halfImage.NewGraphics2D().Render(unscaledSourceImage, 0, 0, 0, halfImage.Width / (double)unscaledSourceImage.Width, halfImage.Height / (double)unscaledSourceImage.Height);
unscaledSourceImage = halfImage;
}
Graphics2D renderGraphics = destImage.NewGraphics2D();
renderGraphics.ImageRenderQuality = Graphics2D.TransformQuality.Best;
renderGraphics.Render(unscaledSourceImage, 0, 0, 0, destImage.Width / (double)unscaledSourceImage.Width, destImage.Height / (double)unscaledSourceImage.Height);
destImage.MarkImageChanged();
return destImage;
}
示例4: Initialize
private void Initialize(ImageBuffer sourceImage, RectangleInt boundsToCopyFrom)
{
if (sourceImage == this)
{
throw new Exception("We do not create a temp buffer for this to work. You must have a source distinct from the dest.");
}
Deallocate();
Allocate(boundsToCopyFrom.Width, boundsToCopyFrom.Height, boundsToCopyFrom.Width * sourceImage.BitDepth / 8, sourceImage.BitDepth);
SetRecieveBlender(sourceImage.GetRecieveBlender());
if (width != 0 && height != 0)
{
RectangleInt DestRect = new RectangleInt(0, 0, boundsToCopyFrom.Width, boundsToCopyFrom.Height);
RectangleInt AbsoluteSourceRect = boundsToCopyFrom;
// The first thing we need to do is make sure the frame is cleared. LBB [3/15/2004]
MatterHackers.Agg.Graphics2D graphics2D = NewGraphics2D();
graphics2D.Clear(new RGBA_Bytes(0, 0, 0, 0));
int x = -boundsToCopyFrom.Left - (int)sourceImage.OriginOffset.x;
int y = -boundsToCopyFrom.Bottom - (int)sourceImage.OriginOffset.y;
graphics2D.Render(sourceImage, x, y, 0, 1, 1);
}
}
示例5: 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());
}