本文整理汇总了C#中UnmanagedImage.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedImage.Clone方法的具体用法?C# UnmanagedImage.Clone怎么用?C# UnmanagedImage.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnmanagedImage
的用法示例。
在下文中一共展示了UnmanagedImage.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessFilter
/// <summary>
/// Process the filter on the specified image.
/// </summary>
///
/// <param name="image">Source image data.</param>
///
protected override unsafe void ProcessFilter( UnmanagedImage image )
{
// copy source image
UnmanagedImage sourceImage = image.Clone( );
// perform closing on the source image
closing.ApplyInPlace( image );
// subtract source image from the closed image
subtract.UnmanagedOverlayImage = sourceImage;
subtract.ApplyInPlace( image );
sourceImage.Dispose( );
}
示例2: Apply
/// <summary>
/// Perform color dithering for the specified image.
/// </summary>
///
/// <param name="sourceImage">Source image to do color dithering for.</param>
///
/// <returns>Returns color dithered image. See <see cref="ColorTable"/> for information about format of
/// the result image.</returns>
///
/// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image. It must 24 or 32 bpp color image.</exception>
///
public Bitmap Apply( UnmanagedImage sourceImage )
{
if ( ( sourceImage.PixelFormat != PixelFormat.Format24bppRgb ) &&
( sourceImage.PixelFormat != PixelFormat.Format32bppRgb ) &&
( sourceImage.PixelFormat != PixelFormat.Format32bppArgb ) &&
( sourceImage.PixelFormat != PixelFormat.Format32bppPArgb ) )
{
throw new UnsupportedImageFormatException( "Unsupported pixel format of the source image." );
}
cache.Clear( );
// make a copy of the original image
UnmanagedImage source = sourceImage.Clone( );
// get image size
width = sourceImage.Width;
height = sourceImage.Height;
stride = sourceImage.Stride;
pixelSize = Bitmap.GetPixelFormatSize( sourceImage.PixelFormat ) / 8;
int offset = stride - width * pixelSize;
// create destination image
Bitmap destImage = new Bitmap( width, height, ( colorTable.Length > 16 ) ?
PixelFormat.Format8bppIndexed : PixelFormat.Format4bppIndexed );
// and init its palette
ColorPalette cp = destImage.Palette;
for ( int i = 0, n = colorTable.Length; i < n; i++ )
{
cp.Entries[i] = colorTable[i];
}
destImage.Palette = cp;
// lock destination image
BitmapData destData = destImage.LockBits( new Rectangle( 0, 0, width, height ),
ImageLockMode.ReadWrite, destImage.PixelFormat );
// pixel values
int r, g, b;
// do the job
unsafe
{
byte* ptr = (byte*) source.ImageData.ToPointer( );
byte* dstBase = (byte*) destData.Scan0.ToPointer( );
byte colorIndex;
bool is8bpp = ( colorTable.Length > 16 );
// for each line
for ( y = 0; y < height; y++ )
{
byte* dst = dstBase + y * destData.Stride;
// for each pixels
for ( x = 0; x < width; x++, ptr += pixelSize )
{
r = ptr[RGB.R];
g = ptr[RGB.G];
b = ptr[RGB.B];
// get color from palette, which is the closest to current pixel's value
Color closestColor = GetClosestColor( r, g, b, out colorIndex );
// do error diffusion
Diffuse( r - closestColor.R, g - closestColor.G, b - closestColor.B, ptr );
// write color index as pixel's value to destination image
if ( is8bpp )
{
*dst = colorIndex;
dst++;
}
else
{
if ( x % 2 == 0 )
{
*dst |= (byte) ( colorIndex << 4 );
}
else
{
*dst |= ( colorIndex );
dst++;
}
}
}
ptr += offset;
}
//.........这里部分代码省略.........