Francisco,<br><br>I can't tell why you got the "Parameter is invalid" error. Perhaps you should try some VB.net forums.<br><br><div class="gmail_quote">2011/4/20 Francisco José Reyes Peralta <span dir="ltr"><<a href="mailto:gistdt08@hotmail.es">gistdt08@hotmail.es</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<font face="Tahoma" size="2">The value of pixelFormat is </font><b style="font-family: Tahoma; font-size: 10pt;">Format24bppRGB</b><div style="font-family: Tahoma; font-size: 10pt;"><br></div><div style="font-family: Tahoma; font-size: 10pt;">
<b></b>Here is the code that I use, but I cannot load into a Bitmap. Maybe I don't undesrtand really how to translate the datasource into a bitmap.</div><div style="font-family: Tahoma; font-size: 10pt;"><br></div><div>
<div><font face="Tahoma" size="2">Public Sub GuardarBitmap(ByRef bmp As Bitmap, ds As Dataset, xOff As Integer, yOff As Integer, width As Integer, height As Integer, _</font></div><div><font face="Tahoma" size="2"> imageWidth As Integer, imageHeight As Integer)</font></div>
<div><font face="Tahoma" size="2"><br></font></div><div><span style="font-family: Tahoma; font-size: 10pt;"><span style="font-size: 10pt;"> Dim bands As Integer() = New Integer(3) {1, 1, 1, 1}</span></span></div><div>
<span style="font-family: Tahoma; font-size: 10pt;"> Dim alpha As Boolean = False</span></div><div><font face="Tahoma" size="2"> Dim index As Boolean = False</font></div><div><font face="Tahoma" size="2"> Dim numChannels As Integer = 1</font></div>
<div><font face="Tahoma" size="2"> Dim channelSize As Integer = 8</font></div><div><font face="Tahoma" size="2"> Dim ctable As ColorTable = Nothing</font></div><div><font face="Tahoma" size="2"><br></font></div>
<div><font face="Tahoma" size="2"> For i As Integer = 0 To ds.RasterCount - 1</font></div><div><font face="Tahoma" size="2"> Dim band As Band = ds.GetRasterBand(i + 1)</font></div><div><font face="Tahoma" size="2"> If Gdal.GetDataTypeSize(band.DataType) > 8 Then</font></div>
<div><font face="Tahoma" size="2"> channelSize = 16</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> Select Case band.GetRasterColorInterpretation()</font></div>
<div><font face="Tahoma" size="2"> Case ColorInterp.GCI_AlphaBand</font></div><div><font face="Tahoma" size="2"> numChannels = 4</font></div><div><font face="Tahoma" size="2"> alpha = True</font></div>
<div><font face="Tahoma" size="2"> bands(3) = i + 1</font></div><div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case ColorInterp.GCI_BlueBand</font></div>
<div><font face="Tahoma" size="2"> If numChannels < 3 Then</font></div><div><font face="Tahoma" size="2"> numChannels = 3</font></div><div><font face="Tahoma" size="2"> End If</font></div>
<div><font face="Tahoma" size="2"> bands(0) = i + 1</font></div><div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case ColorInterp.GCI_RedBand</font></div>
<div><font face="Tahoma" size="2"> If numChannels < 3 Then</font></div><div><font face="Tahoma" size="2"> numChannels = 3</font></div><div><font face="Tahoma" size="2"> End If</font></div>
<div><font face="Tahoma" size="2"> bands(2) = i + 1</font></div><div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case ColorInterp.GCI_GreenBand</font></div>
<div><font face="Tahoma" size="2"> If numChannels < 3 Then</font></div><div><font face="Tahoma" size="2"> numChannels = 3</font></div><div><font face="Tahoma" size="2"> End If</font></div>
<div><font face="Tahoma" size="2"> bands(1) = i + 1</font></div><div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case ColorInterp.GCI_PaletteIndex</font></div>
<div><font face="Tahoma" size="2"> ctable = band.GetRasterColorTable()</font></div><div><font face="Tahoma" size="2"> index = True</font></div><div><font face="Tahoma" size="2"> bands(0) = i + 1</font></div>
<div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case ColorInterp.GCI_GrayIndex</font></div><div><font face="Tahoma" size="2"> index = True</font></div>
<div><font face="Tahoma" size="2"> bands(0) = i + 1</font></div><div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> Case Else</font></div>
<div><font face="Tahoma" size="2"> If i < 4 AndAlso bands(i) = 0 Then</font></div><div><font face="Tahoma" size="2"> If numChannels < i Then</font></div><div><font face="Tahoma" size="2"> numChannels = i</font></div>
<div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> bands(i) = i + 1</font></div><div><font face="Tahoma" size="2"> End If</font></div>
<div><font face="Tahoma" size="2"> Exit Select</font></div><div><font face="Tahoma" size="2"> End Select</font></div><div><font face="Tahoma" size="2"> Next</font></div><div><font face="Tahoma" size="2"><br>
</font></div><div><font face="Tahoma" size="2"> Dim pixelFormat__1 As PixelFormat</font></div><div><font face="Tahoma" size="2"> Dim dataType__2 As DataType</font></div><div><font face="Tahoma" size="2"> Dim pixelSpace As Integer</font></div>
<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> If index Then</font></div><div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format8bppIndexed</font></div>
<div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_Byte</font></div><div><font face="Tahoma" size="2"> pixelSpace = 1</font></div><div><font face="Tahoma" size="2"> Else</font></div>
<div><font face="Tahoma" size="2"> If numChannels = 1 Then</font></div><div><font face="Tahoma" size="2"> If channelSize > 8 Then</font></div><div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format16bppGrayScale</font></div>
<div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_Int16</font></div><div><font face="Tahoma" size="2"> pixelSpace = 2</font></div><div><font face="Tahoma" size="2"> Else</font></div>
<div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format24bppRgb</font></div><div><font face="Tahoma" size="2"> numChannels = 3</font></div><div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_Byte</font></div>
<div class="im"><div><font face="Tahoma" size="2"> pixelSpace = 3</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> Else</font></div>
</div><div><font face="Tahoma" size="2"> If alpha Then</font></div><div><font face="Tahoma" size="2"> If channelSize > 8 Then</font></div><div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format64bppArgb</font></div>
<div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_UInt16</font></div><div><font face="Tahoma" size="2"> pixelSpace = 8</font></div><div><font face="Tahoma" size="2"> Else</font></div>
<div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format32bppArgb</font></div><div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_Byte</font></div><div>
<font face="Tahoma" size="2"> pixelSpace = 4</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> numChannels = 4</font></div>
<div class="im"><div><font face="Tahoma" size="2"> Else</font></div><div><font face="Tahoma" size="2"> If channelSize > 8 Then</font></div></div><div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format48bppRgb</font></div>
<div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_UInt16</font></div><div><font face="Tahoma" size="2"> pixelSpace = 6</font></div><div><font face="Tahoma" size="2"> Else</font></div>
<div><font face="Tahoma" size="2"> pixelFormat__1 = PixelFormat.Format24bppRgb</font></div><div><font face="Tahoma" size="2"> dataType__2 = DataType.GDT_Byte</font></div><div>
<font face="Tahoma" size="2"> pixelSpace = 3</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> numChannels = 3</font></div>
<div class="im"><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"><br>
</font></div><div><font face="Tahoma" size="2"><br></font></div></div><div class="im"><div><font face="Tahoma" size="2"> Dim bitmap As New Bitmap(imageWidth, imageHeight, pixelFormat__1)</font></div><div><font face="Tahoma" size="2"><br>
</font></div></div><div><font face="Tahoma" size="2"> If index Then</font></div><div><font face="Tahoma" size="2"> If ctable IsNot Nothing Then</font></div><div><font face="Tahoma" size="2"> Dim iCol As Integer = ctable.GetCount()</font></div>
<div><font face="Tahoma" size="2"> Dim pal As ColorPalette = bitmap.Palette</font></div><div><font face="Tahoma" size="2"> For i As Integer = 0 To iCol - 1</font></div><div><font face="Tahoma" size="2"> Dim ce As ColorEntry = ctable.GetColorEntry(i)</font></div>
<div><font face="Tahoma" size="2"> pal.Entries(i) = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3)</font></div><div><font face="Tahoma" size="2"> Next</font></div><div><font face="Tahoma" size="2"> bitmap.Palette = pal</font></div>
<div><font face="Tahoma" size="2"> Else</font></div><div><font face="Tahoma" size="2"> Dim pal As ColorPalette = bitmap.Palette</font></div><div><font face="Tahoma" size="2"> For i As Integer = 0 To 255</font></div>
<div><font face="Tahoma" size="2"> pal.Entries(i) = Color.FromArgb(255, i, i, i)</font></div><div><font face="Tahoma" size="2"> Next</font></div><div><font face="Tahoma" size="2"> bitmap.Palette = pal</font></div>
<div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"> End If</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> Dim bitmapData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, imageWidth, imageHeight), ImageLockMode.ReadWrite, pixelFormat__1)</font></div>
<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> Try</font></div><div><font face="Tahoma" size="2"> Dim strideBMD As Integer = bitmapData.Stride</font></div><div><font face="Tahoma" size="2"> Dim buf As IntPtr = bitmapData.Scan0</font></div>
<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> ds.ReadRaster(xOff, yOff, width, height, buf, imageWidth, _</font></div><div><font face="Tahoma" size="2"> imageHeight, dataType__2, numChannels, bands, pixelSpace, strideBMD, _</font></div>
<div><font face="Tahoma" size="2"> 1)</font></div><div><font face="Tahoma" size="2"> Finally</font></div><div><font face="Tahoma" size="2"> bitmap.UnlockBits(bitmapData)</font></div><div><font face="Tahoma" size="2"> End Try</font></div>
<div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> bmp = bitmap</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> End Sub</font></div>
</div><div style="font-family: Tahoma; font-size: 10pt;"><br></div><div style="font-family: Tahoma; font-size: 10pt;">Thanks in advanced.</div><div style="font-family: Tahoma; font-size: 10pt;"><br></div><div style="font-family: Tahoma; font-size: 10pt;">
Francisco J.<br><br>Date: Tue, 19 Apr 2011 16:10:27 +0200<div class="im"><br>Subject: Re: [gdal-dev] Problem with GDALDatasetRasterIO.cs and ECW files<br></div>From: <a href="mailto:szekerest@gmail.com" target="_blank">szekerest@gmail.com</a><br>
To: <a href="mailto:gistdt08@hotmail.es" target="_blank">gistdt08@hotmail.es</a><br>CC: <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><div><div></div><div class="h5"><br><br>Not sure what is the actual value of 'pixelFormat__1' in your program.<br>
<br>Best regards,<br><br>Tamas<br><br><br><div>2011/4/19 Francisco José Reyes Peralta <span dir="ltr"><<a href="mailto:gistdt08@hotmail.es" target="_blank">gistdt08@hotmail.es</a>></span><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
<pre style="font-family: 'Times New Roman'; font-size: 12pt;">The parameter is not valid is the error that I get.</pre><pre style="font-family: 'Times New Roman'; font-size: 12pt;">I use an adaptation of the source .cs code in <a href="http://VB.NET" target="_blank">VB.NET</a>.</pre>
<pre style="font-family: 'Times New Roman'; font-size: 12pt;">Here is part of the code:</pre><pre><span style="font-size: 21px;"><br></span></pre><pre><font size="4"> Dim pixelFormat As PixelFormat</font></pre>
<pre><font size="4"><span style="white-space: pre-wrap;">        </span>Dim dataType As DataType
Dim pixelSpace As Integer
If isIndexed Then
pixelFormat = PixelFormat.Format8bppIndexed
dataType = DataType.GDT_Byte
pixelSpace = 1
Else
If channelCount = 1 Then
If channelSize > 8 Then
pixelFormat = PixelFormat.Format16bppGrayScale
dataType = DataType.GDT_Int16
pixelSpace = 2
Else
pixelFormat = PixelFormat.Format24bppRgb
channelCount = 3
dataType = DataType.GDT_Byte
pixelSpace = 3
End If
Else
If hasAlpha Then
If channelSize > 8 Then
pixelFormat = PixelFormat.Format64bppArgb
dataType = DataType.GDT_UInt16
pixelSpace = 8
Else
pixelFormat = PixelFormat.Format32bppArgb
dataType = DataType.GDT_Byte
pixelSpace = 4
End If
channelCount = 4
Else
If channelSize > 8 Then
pixelFormat = PixelFormat.Format48bppRgb
dataType = DataType.GDT_UInt16
pixelSpace = 6
Else
pixelFormat = PixelFormat.Format24bppRgb
dataType = DataType.GDT_Byte
pixelSpace = 3
End If
channelCount = 3
End If
End If
End If
<b><span style="font-weight: normal;"><b><span style="font-family: 'Times New Roman'; font-weight: normal; white-space: normal; font-size: medium;"><pre style="text-indent: 0px ! important; font-family: 'Times New Roman'; font-size: 12pt; display: inline ! important;">
And the Error is in the following line:</pre></span></b></span></b></font></pre><pre><font size="4">
Dim bitmap As New Bitmap(imageWidth, imageHeight, pixelFormat__1)</font></pre><pre><font size="4"><br></font></pre><pre><font size="4"><font face="'Times New Roman'">Is possible to read the dataset and write to a bitmap or picturebox without save as file?</font></font></pre>
<pre><font size="4"><font face="'Times New Roman'"><br></font></font></pre><pre><font size="4">Thanks for your reply.</font></pre><pre><font size="4"><br></font></pre><pre><font size="4">Francisco J.</font></pre>
<pre><font size="4"><br></font></pre><pre><font size="4"><br></font></pre><pre style="font-family: 'Times New Roman'; font-size: 12pt;">2011/4/19 Francisco José Reyes Peralta <<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">gistdt08 at hotmail.es</a>>
><i> Dear friends, I'm vieweing the *GDALDatasetRasterIO.cs* from the Csharp
</i>><i> samples of GDAL and I'm getting an error in the following line *Bitmap
</i>><i> bitmap = new Bitmap(imageWidth, imageHeight, pixelFormat);* In the *
</i>><i> pixelFormat* argument.
</i>><i>
</i>
Hi,
What is the error message specifically?
Best regards,
Tamas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <a href="http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110419/cc8baab2/attachment-0001.html" target="_blank">http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110419/cc8baab2/attachment-0001.html</a></pre>
                                           </div>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br><div style="padding: 0px; margin-left: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;">
</div></div></div></div>                                            </div>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>
/tʃaɪθənjə/ /kʊmɑr/ <br>+91-9494447584<br>17.2416N 80.1426E<br>