Hi list,<br>I solved my problem debugging gdalJNI.dll.<br><br>Since the SWIG Java Bindings use the method &quot;GetDirectBufferAddress(...)&quot; which requires a direct buffer,<br>I fixed the code:<br>------------------------------------------------------------------------------------------------------------------------------------------
<br>...<br>byte [] byteRaster = ((DataBufferByte)b0.getData().getDataBuffer()).getData();<br>ByteBuffer bb=ByteBuffer.allocateDirect(byteRaster.length);<br>bb.put(byteRaster);<br>...<br>------------------------------------------------------------------------------------------------------------------------------------------
<br><br>The old code was:<br>------------------------------------------------------------------------------------------------------------------------------------------<br><span>...<br>ByteBuffer bb0 = ByteBuffer.wrap(((DataBufferByte) 
b0.getData().getDataBuffer()).getData(0));
<br>...<br><br>which uses a HeapByteBuffer. In such a case, GetDirectBufferAddress returns NULL.<br></span>------------------------------------------------------------------------------------------------------------------------------------------
<br><br><br>With these changes, the final code becomes:<br>------------------------------------------------------------------------------------------------------------------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final File outFile = new File(&quot;D:\\DatiPlugin\\geotiff\\mysample.tif&quot;);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; final BufferedImage im = ImageIO.read(new File(&quot;D:\\DatiPlugin\\bogota.tif&quot;));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Driver gtiffDriver = gdal.GetDriverByName(&quot;<span>GTiff</span>&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; final int width = im.getWidth
();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; final int height = im.getHeight();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dataset ds = gtiffDriver.Create(outFile.getAbsolutePath(), width, height, 1, gdalconstConstants.GDT_Byte,null);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RenderedOp b0 = BandSelectDescriptor.create
(im, new int[] { 0 }, null);<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; byte [] byteRaster = ((DataBufferByte)b0.getData().getDataBuffer()).getData();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ByteBuffer bb=ByteBuffer.allocateDirect(byteRaster.length);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; bb.put(byteRaster);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ds.GetRasterBand(1).WriteRaster_Direct(0,0,width,height,width,height,gdalconstConstants.GDT_Byte,bb);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ds.FlushCache();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ds.delete();<br>------------------------------------------------------------------------------------------------------------------------------------------
<br><br><br><br><br><br><br><br><div><span class="gmail_quote">On 12/27/06, <b class="gmail_sendername">Daniele Romagnoli</b> &lt;<a href="mailto:dany.geotools@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

dany.geotools@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">Hi list,<br><br>I&#39;m unsuccessfully trying to write some raster data using &nbsp;GDAL Java
<br>Bindings, by mean of the writeRaster_Direct method.<br></div><div style="direction: ltr;"><span>
<br>This is my code:<br>------------------------------------------------------------<br>final File outFile = new File(&quot;d:\\DatiPlugin\\geotiff\\mysample22.tif&quot;);<br>final BufferedImage im = ImageIO.read(new File(&quot;D:\\DatiPlugin\\bogota.tif&quot;));
<br><br>Driver gtiffDriver = gdal.GetDriverByName(&quot;GTiff&quot;);<br>final int width = im.getWidth();<br>final int height = im.getHeight ();<br><br>Dataset ds = gtiffDriver.Create(outFile.getAbsolutePath(), width,<br>


height, 1, gdalconstConstants.GDT_Byte,null);<br><br>RenderedOp b0 = BandSelectDescriptor.create(im, new int[] { 0 }, null);<br><br>ByteBuffer bb0 = ByteBuffer.wrap(((DataBufferByte)<br>b0.getData().getDataBuffer()).getData(0));
<br><br>ByteBuffer scanline;<br>byte &nbsp;miniBuffer[] = new byte [width];<br><br>for (int i=0; i&lt;height;i++){<br> &nbsp; &nbsp;bb0.get(miniBuffer, width*i, width);<br> &nbsp; &nbsp;scanline = ByteBuffer.wrap(miniBuffer);<br> &nbsp; &nbsp;ds.GetRasterBand


(1).WriteRaster_Direct(0,height*i,width,1,width,1,gdalconstConstants.GDT_Byte,scanline);<br>}<br><br><br></span>ds.FlushCache();<br>ds.delete();<br><span>------------------------------------------------------------
<br><br><br><br></span></div><div style="direction: ltr;">This code, generates this exception:<br></div><div style="direction: ltr;"><div><span>-------------------------------------------------------
<br></span></div><span>An unexpected exception has been detected in native code outside the VM.<br>Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred<br>at PC=0x7C342EEE
<br>Function=memcpy+0x33<br>Library=C:\WINDOWS\system32\MSVCR71.dll<br>Source file = F:\VS70Builds\3052\vc\crtbld\crt\src\intel\memcpy.asm : 171<br><br><br>Current Java thread:<br> &nbsp; &nbsp;at org.gdal.gdal.gdalJNI.Band_WriteRaster_Direct


 (Native Method)<br> &nbsp; &nbsp;at org.gdal.gdal.Band.WriteRaster_Direct(Band.java:127)<br> &nbsp; &nbsp;at javax.imageio.plugins.jp2k.TestJaiRead.testWrite(TestJaiRead.java:178)<br> &nbsp; &nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<br> &nbsp; &nbsp;at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br> &nbsp; &nbsp;at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br> &nbsp; &nbsp;at java.lang.reflect.Method.invoke


 (Method.java:324)<br> &nbsp; &nbsp;at junit.framework.TestCase.runTest(TestCase.java:154)<br> &nbsp; &nbsp;at junit.framework.TestCase.runBare(TestCase.java:127)<br> &nbsp; &nbsp;at junit.framework.TestResult$1.protect(TestResult.java:106)<br> &nbsp; &nbsp;at 
junit.framework.TestResult.runProtected (TestResult.java:124)<br> &nbsp; &nbsp;at junit.framework.TestResult.run(TestResult.java:109)<br> &nbsp; &nbsp;at junit.framework.TestCase.run(TestCase.java:118)<br> &nbsp; &nbsp;at junit.framework.TestSuite.runTest


(TestSuite.java:208)<br> &nbsp; &nbsp;at junit.framework.TestSuite.run (TestSuite.java:203)<br> &nbsp; &nbsp;at junit.textui.TestRunner.doRun(TestRunner.java:116)<br> &nbsp; &nbsp;at junit.textui.TestRunner.doRun(TestRunner.java:109)<br> &nbsp; &nbsp;at junit.textui.TestRunner.run


(TestRunner.java:72)<br> &nbsp; &nbsp;at junit.textui.TestRunner.run (TestRunner.java:57)<br> &nbsp; &nbsp;at javax.imageio.plugins.jp2k.TestJaiRead.main(TestJaiRead.java:76)<br>------------------------------------------<br><br><br></span></div>


Does anybody have any clues about what I&#39;m doing wrong?<br><br>Moreover, I have one question. Did anybody tried to write data using<br>the java bindings directly? &nbsp;I mean without using DataSet CreateCopy or the<br>like but feeding data directly into a RasterBand?
<br><br><br>Best regards,<br>Daniele<br><br><br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br clear="all"><br><br><br><br><br>-- <br>Best Regards,<br><span>Daniele


</span></blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br>Daniele