java gdal dataset.readraster_#3073 ([PATCH - C#] Dataset.ReadRaster()/WriteRaster() doesn't work on ...

Tamas,

The Marshal.AllocHGlobal and Marshal.Copy calls in Dataset.ReadRaster?()/WriteRaster?() mainly forget to multiply the pixel count by the number of bands, thus only the data for the first band is correctly read/written for pixel-interleaved buffers. Attached a patch that fixes the issue (adapted from gdal_java.i). I've also better taken into account the pixelSpace, lineSpace and bandSpace parameters to compute the number of elements to copy, as done in BandRasterIO_Validate and DatasetRasterIO_Validate in gdal_java.i. Currently, this wouldn't work with exotic values of spacings.

With that patch, the following code snippet does produce a pink image :

using System;

using OSGeo.GDAL;

class test

{

public static void Main(string[] args)

{

Gdal.AllRegister();

Driver drv = Gdal.GetDriverByName("GTiff");

int iWidth = 100;

int iHeight = 100;

Dataset ds_new = drv.Create("testrgb.tif", iWidth, iHeight, 3, DataType.GDT_Byte, new string[] { });

byte[] buffers = new byte[(iHeight * iWidth) * 3];

int i, j;

for(i=0;i

{

for(j=0;j

{

buffers[(i*iWidth+j)] = 255;

buffers[100*100+(i*iWidth+j)] = 0;

buffers[2*100*100+(i*iWidth+j)] = 255;

}

}

int[] iBandMap = { 1, 2, 3 };

ds_new.WriteRaster(0, 0, iWidth, iHeight, buffers, iWidth, iHeight, 3, iBandMap, 0, 0, 0);

ds_new = null;

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值