C#+ArcEngine:生成图像( ArGIS10.1、VS2010 窗体+代码)

分享给有需要的人,代码质量勿喷。

1、生成JPG图像

internal void xjOutputJPG(Hashtable HtNor, LInfo xjlLASInfo, string ExportLasFullName)
{
    int SumRow = xjlLASInfo.SumRow;
    int SumCol = xjlLASInfo.SumCol;
    Bitmap xjBitmap = new Bitmap(SumCol, SumRow);
    for (int i = 0; i < SumCol; i++)//列数
    {
        for (int j = 0; j < SumRow; j++)//行数
        {
            int GridIndex = (SumRow - j - 1) * SumCol + (i + 1);
            Byte GridValueTempByte = Convert.ToByte(HtNor[GridIndex]);
            xjBitmap.SetPixel(i, j, Color.FromArgb(GridValueTempByte, GridValueTempByte, GridValueTempByte));
        }
    }
    xjBitmap.Save(ExportLasFullName);
}

2、生成TIFF图像

internal void xjOutputTiff(Hashtable HtNor, LInfo xjLASInfo, string ExportLasFullName)
{
    string xjOutRasterPath = System.IO.Path.GetDirectoryName(ExportLasFullName);
    IRasterDataset xjOutRasterDataset = CreateRasterDataset(xjOutRasterPath, ExportLasFullName, xjLASInfo, HtNor);
    IRasterLayer xjOutRasterLayer = new RasterLayerClass();
    xjOutRasterLayer.CreateFromDataset(xjOutRasterDataset);
    ILayer xjOutLayer = xjOutRasterLayer;
    xjOutRasterLayer.Name = ExportLasFullName;
}
private IRasterDataset CreateRasterDataset(string FileDirectoryName, string FielName, 
                                           LInfo xjLASInfo, Hashtable G_Hashtable)
{
    //原点
    IPoint xjOriginPoint = new PointClass();
    xjOriginPoint.PutCoords(xjLASInfo.G_Xmin, xjLASInfo.G_Ymin);

    //创建数据集
    IWorkspaceFactory xjWorkspaceFactory = new RasterWorkspaceFactoryClass();
    IRasterWorkspace2 xjRasterWorkspace = xjWorkspaceFactory.OpenFromFile(FileDirectoryName, 0) as IRasterWorkspace2;
    IRasterDataset xjRasterDataset = xjRasterWorkspace.CreateRasterDataset(FielName, "TIFF", 
          xjOriginPoint, xjLASInfo.G_ColumnSum, xjLASInfo.G_RowSum, xjLASInfo.G_GridSide, xjLASInfo.G_GridSide, 
          1, rstPixelType.PT_DOUBLE, new UnknownCoordinateSystemClass(), true);


    IRasterBandCollection xjRasterBandCollection = (IRasterBandCollection)xjRasterDataset;
    IRasterBand xjRasterBand = xjRasterBandCollection.Item(0);
    IRasterProps xjRasterProps = (IRasterProps)xjRasterBand;
    xjRasterProps.NoDataValue = -1.0;

    IPnt RD_PntPixelBlockOrigin = new DblPntClass();
    RD_PntPixelBlockOrigin.SetCoords(0, 0);
    IPnt RD_PntPixelBlockSize = new DblPntClass();
    RD_PntPixelBlockSize.SetCoords(xjRasterProps.Width, xjRasterProps.Height);//(列数,行数)

    IRawPixels xjRawPixels = (IRawPixels)xjRasterBandCollection.Item(0);
    IPixelBlock3 xjPixelBlock3 = (IPixelBlock3)xjRawPixels.CreatePixelBlock(RD_PntPixelBlockSize);
    xjRawPixels.Read(RD_PntPixelBlockOrigin, (IPixelBlock)xjPixelBlock3);

    System.Array xjPixelData = (System.Array)xjPixelBlock3.get_PixelDataByRef(0);
    for (int i = 0; i < xjRasterProps.Width; i++)//列数
    {
        for (int j = 0; j < xjRasterProps.Height; j++)//行数
        {
            int GridIndex = (xjLASInfo.G_RowSum - j - 1) * xjLASInfo.G_ColumnSum + (i + 1);

            if (G_Hashtable.Contains(GridIndex))
            {
                double GridValueTemp = Convert.ToDouble(G_Hashtable[GridIndex]);
                xjPixelData.SetValue(GridValueTemp, i, j);
            }
            else
            {
                xjPixelData.SetValue(-1.0, i, j);
            }
        }
    }

    xjPixelBlock3.set_PixelData(0, (System.Object)xjPixelData);
    byte[] xjNoDataArray = (byte[])xjPixelBlock3.get_NoDataMaskByRef(0);
    xjPixelBlock3.set_NoDataMask(0, (System.Object)xjNoDataArray);

    System.Object xjCachePointer = xjRawPixels.AcquireCache();
    xjRawPixels.Write(RD_PntPixelBlockOrigin, (IPixelBlock)xjPixelBlock3);
    xjRawPixels.ReturnCache(xjCachePointer);

    return xjRasterDataset;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

累了就要打游戏

把我养胖,搞代码

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值