本文整理汇总了C#中OSGeo.GDAL.Dataset.ReadRaster方法的典型用法代码示例。如果您正苦于以下问题:C# Dataset.ReadRaster方法的具体用法?C# Dataset.ReadRaster怎么用?C# Dataset.ReadRaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSGeo.GDAL.Dataset
的用法示例。
在下文中一共展示了Dataset.ReadRaster方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveBitmapDirect
//.........这里部分代码省略.........
else
{
if (channelCount == 1)
{
if (channelSize > 8)
{
pixelFormat = PixelFormat.Format16bppGrayScale;
dataType = DataType.GDT_Int16;
pixelSpace = 2;
}
else
{
pixelFormat = PixelFormat.Format24bppRgb;
channelCount = 3;
dataType = DataType.GDT_Byte;
pixelSpace = 3;
}
}
else
{
if (hasAlpha)
{
if (channelSize > 8)
{
pixelFormat = PixelFormat.Format64bppArgb;
dataType = DataType.GDT_UInt16;
pixelSpace = 8;
}
else
{
pixelFormat = PixelFormat.Format32bppArgb;
dataType = DataType.GDT_Byte;
pixelSpace = 4;
}
channelCount = 4;
}
else
{
if (channelSize > 8)
{
pixelFormat = PixelFormat.Format48bppRgb;
dataType = DataType.GDT_UInt16;
pixelSpace = 6;
}
else
{
pixelFormat = PixelFormat.Format24bppRgb;
dataType = DataType.GDT_Byte;
pixelSpace = 3;
}
channelCount = 3;
}
}
}
// Create a Bitmap to store the GDAL image in
Bitmap bitmap = new Bitmap(imageWidth, imageHeight, pixelFormat);
if (isIndexed)
{
// setting up the color table
if (ct != null)
{
int iCol = ct.GetCount();
ColorPalette pal = bitmap.Palette;
for (int i = 0; i < iCol; i++)
{
ColorEntry ce = ct.GetColorEntry(i);
pal.Entries[i] = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3);
}
bitmap.Palette = pal;
}
else
{
// grayscale
ColorPalette pal = bitmap.Palette;
for (int i = 0; i < 256; i++)
pal.Entries[i] = Color.FromArgb(255, i, i, i);
bitmap.Palette = pal;
}
}
// Use GDAL raster reading methods to read the image data directly into the Bitmap
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, imageWidth, imageHeight), ImageLockMode.ReadWrite, pixelFormat);
try
{
int stride = bitmapData.Stride;
IntPtr buf = bitmapData.Scan0;
ds.ReadRaster(xOff, yOff, width, height, buf, imageWidth, imageHeight, dataType,
channelCount, bandMap, pixelSpace, stride, 1);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
bitmap.Save(filename);
}
示例2: LoadBitmapDirect
private static void LoadBitmapDirect(Dataset ds, Bitmap bitmap, int xOff, int yOff, int width, int height, int imageWidth, int imageHeight, int iOverview)
{
if (isIndexed)
{
// setting up the color table
if (ct != null)
{
int iCol = ct.GetCount();
ColorPalette pal = bitmap.Palette;
for (int i = 0; i < iCol; i++)
{
ColorEntry ce = ct.GetColorEntry(i);
pal.Entries[i] = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3);
}
bitmap.Palette = pal;
}
else
{
// grayscale
ColorPalette pal = bitmap.Palette;
for (int i = 0; i < 256; i++)
pal.Entries[i] = Color.FromArgb(255, i, i, i);
bitmap.Palette = pal;
}
}
// Use GDAL raster reading methods to read the image data directly into the Bitmap
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, imageWidth, imageHeight), ImageLockMode.ReadWrite, pixelFormat);
try
{
int stride = bitmapData.Stride;
IntPtr buf = bitmapData.Scan0;
ds.ReadRaster(xOff, yOff, width, height, buf, imageWidth, imageHeight, dataType,
channelCount, bandMap, pixelSpace, stride, 1);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
}