本文整理汇总了C#中ImageData.CopyValuesToBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# ImageData.CopyValuesToBitmap方法的具体用法?C# ImageData.CopyValuesToBitmap怎么用?C# ImageData.CopyValuesToBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageData
的用法示例。
在下文中一共展示了ImageData.CopyValuesToBitmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadPaletteBuffered
private void ReadPaletteBuffered()
{
ColorTable ct = _red.GetRasterColorTable();
if (ct == null)
{
throw new GdalException("Image was stored with a palette interpretation but has no color table.");
}
if (ct.GetPaletteInterpretation() != PaletteInterp.GPI_RGB)
{
throw new GdalException("Only RGB palette interpreation is currently supported by this plugin, " + ct.GetPaletteInterpretation() + " is not supported.");
}
int tw = TileCollection.TileWidth;
int th = TileCollection.TileHeight;
for (int row = 0; row < TileCollection.NumTilesTall(); row++)
{
for (int col = 0; col < TileCollection.NumTilesWide(); col++)
{
// takes into account that right and bottom tiles might be smaller.
int width = TileCollection.GetTileWidth(col);
int height = TileCollection.GetTileHeight(row);
ImageData id = new ImageData();
byte[] red = new byte[width * height];
_red.ReadRaster(col * tw, row * th, width, height, red, width, height, 0, 0);
Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb);
BitmapData bData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
Stride = bData.Stride;
image.UnlockBits(bData);
const int bpp = 4;
int stride = Stride;
byte[] vals = new byte[width * height * 4];
byte[][] colorTable = new byte[256][];
for (int i = 0; i < 255; i++)
{
ColorEntry ce = ct.GetColorEntry(i);
colorTable[i] = new[] { (byte)ce.c3, (byte)ce.c2, (byte)ce.c1, (byte)ce.c4 };
}
for (int r = 0; r < height; r++)
{
for (int c = 0; c < width; c++)
{
Array.Copy(colorTable[red[c + r * width]], 0, vals, row * stride + col * bpp, 4);
}
}
id.Values = vals;
id.CopyValuesToBitmap();
TileCollection.Tiles[row, col] = id;
}
}
SetTileBounds(Bounds.AffineCoefficients);
}