[gdal-dev] Problem with GDALDatasetRasterIO.cs and ECW files

Francisco José Reyes Peralta gistdt08 at hotmail.es
Wed Apr 20 02:13:43 EDT 2011


The value of pixelFormat is Format24bppRGB
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.
Public Sub GuardarBitmap(ByRef bmp As Bitmap, ds As Dataset, xOff As Integer, yOff As Integer, width As Integer, height As Integer, _                             imageWidth As Integer, imageHeight As Integer)
        Dim bands As Integer() = New Integer(3) {1, 1, 1, 1}        Dim alpha As Boolean = False        Dim index As Boolean = False        Dim numChannels As Integer = 1        Dim channelSize As Integer = 8        Dim ctable As ColorTable = Nothing
        For i As Integer = 0 To ds.RasterCount - 1            Dim band As Band = ds.GetRasterBand(i + 1)            If Gdal.GetDataTypeSize(band.DataType) > 8 Then                channelSize = 16            End If            Select Case band.GetRasterColorInterpretation()                Case ColorInterp.GCI_AlphaBand                    numChannels = 4                    alpha = True                    bands(3) = i + 1                    Exit Select                Case ColorInterp.GCI_BlueBand                    If numChannels < 3 Then                        numChannels = 3                    End If                    bands(0) = i + 1                    Exit Select                Case ColorInterp.GCI_RedBand                    If numChannels < 3 Then                        numChannels = 3                    End If                    bands(2) = i + 1                    Exit Select                Case ColorInterp.GCI_GreenBand                    If numChannels < 3 Then                        numChannels = 3                    End If                    bands(1) = i + 1                    Exit Select                Case ColorInterp.GCI_PaletteIndex                    ctable = band.GetRasterColorTable()                    index = True                    bands(0) = i + 1                    Exit Select                Case ColorInterp.GCI_GrayIndex                    index = True                    bands(0) = i + 1                    Exit Select                Case Else                    If i < 4 AndAlso bands(i) = 0 Then                        If numChannels < i Then                            numChannels = i                        End If                        bands(i) = i + 1                    End If                    Exit Select            End Select        Next
        Dim pixelFormat__1 As PixelFormat        Dim dataType__2 As DataType        Dim pixelSpace As Integer
        If index Then            pixelFormat__1 = PixelFormat.Format8bppIndexed            dataType__2 = DataType.GDT_Byte            pixelSpace = 1        Else            If numChannels = 1 Then                If channelSize > 8 Then                    pixelFormat__1 = PixelFormat.Format16bppGrayScale                    dataType__2 = DataType.GDT_Int16                    pixelSpace = 2                Else                    pixelFormat__1 = PixelFormat.Format24bppRgb                    numChannels = 3                    dataType__2 = DataType.GDT_Byte                    pixelSpace = 3                End If            Else                If alpha Then                    If channelSize > 8 Then                        pixelFormat__1 = PixelFormat.Format64bppArgb                        dataType__2 = DataType.GDT_UInt16                        pixelSpace = 8                    Else                        pixelFormat__1 = PixelFormat.Format32bppArgb                        dataType__2 = DataType.GDT_Byte                        pixelSpace = 4                    End If                    numChannels = 4                Else                    If channelSize > 8 Then                        pixelFormat__1 = PixelFormat.Format48bppRgb                        dataType__2 = DataType.GDT_UInt16                        pixelSpace = 6                    Else                        pixelFormat__1 = PixelFormat.Format24bppRgb                        dataType__2 = DataType.GDT_Byte                        pixelSpace = 3                    End If                    numChannels = 3                End If            End If        End If

        Dim bitmap As New Bitmap(imageWidth, imageHeight, pixelFormat__1)
        If index Then            If ctable IsNot Nothing Then                Dim iCol As Integer = ctable.GetCount()                Dim pal As ColorPalette = bitmap.Palette                For i As Integer = 0 To iCol - 1                    Dim ce As ColorEntry = ctable.GetColorEntry(i)                    pal.Entries(i) = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3)                Next                bitmap.Palette = pal            Else                Dim pal As ColorPalette = bitmap.Palette                For i As Integer = 0 To 255                    pal.Entries(i) = Color.FromArgb(255, i, i, i)                Next                bitmap.Palette = pal            End If        End If
        Dim bitmapData As BitmapData = bitmap.LockBits(New Rectangle(0, 0, imageWidth, imageHeight), ImageLockMode.ReadWrite, pixelFormat__1)
        Try            Dim strideBMD As Integer = bitmapData.Stride            Dim buf As IntPtr = bitmapData.Scan0
            ds.ReadRaster(xOff, yOff, width, height, buf, imageWidth, _             imageHeight, dataType__2, numChannels, bands, pixelSpace, strideBMD, _             1)        Finally            bitmap.UnlockBits(bitmapData)        End Try
        bmp = bitmap
    End Sub
Thanks in advanced.
Francisco J.

Date: Tue, 19 Apr 2011 16:10:27 +0200
Subject: Re: [gdal-dev] Problem with GDALDatasetRasterIO.cs and ECW files
From: szekerest at gmail.com
To: gistdt08 at hotmail.es
CC: gdal-dev at lists.osgeo.org

Not sure what is the actual value of 'pixelFormat__1' in your program.

Best regards,

Tamas


2011/4/19 Francisco José Reyes Peralta <gistdt08 at hotmail.es>






The parameter is not valid is the error that I get.I use an adaptation of the source .cs code in VB.NET.
Here is part of the code:
        Dim pixelFormat As PixelFormat	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

And the Error is in the following line:
Dim bitmap As New Bitmap(imageWidth, imageHeight, pixelFormat__1)
Is possible to read the dataset and write to a bitmap or picturebox without save as file?

Thanks for your reply.
Francisco J.

2011/4/19 Francisco José Reyes Peralta <gistdt08 at hotmail.es>

>  Dear friends, I'm vieweing the *GDALDatasetRasterIO.cs* from the Csharp
> samples of GDAL and I'm getting an error in the following line *Bitmap
> bitmap = new Bitmap(imageWidth, imageHeight, pixelFormat);* In the *
> pixelFormat* argument.
>

Hi,

What is the error message specifically?

Best regards,

Tamas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110419/cc8baab2/attachment-0001.html
 		 	   		  

_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org

http://lists.osgeo.org/mailman/listinfo/gdal-dev


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110420/6a2b7023/attachment-0001.html


More information about the gdal-dev mailing list