Я пытаюсь отобразить растровое изображение в элементе управления OpenGL под названием GL (в качестве оболочки используется SharpGL). На практике текстовая строка записывается в поле GDI + Picture, из которого получается растровое изображение. Для функции GLBitmap требуется входной массив Byte (); Я преобразую растровое изображение в массив Byte (). Кажется, не работает, поскольку я получаю кучу точек на экране. Я также сохранил изображение PictureBox в файл Bmp на диске и проверил, что оно имеет желаемый контент. Таким образом, изображение Bmp здесь не является проблемой.
Фактический дисплей OpenGL
Файл Bmp создан из кода ниже
Интересно, что Я делаю не так У кого-нибудь было бы предложение? Заранее спасибо.
Код VB. Net приведен ниже.
' Create Bitmap & Graphics context for string
'
' iWidth and iHeight are the dimensions of the bitmap;
' they are a power of 2.
Dim SharpBMap As Bitmap = New Bitmap(iWidth, iHeight)
Dim SharpGraf As Graphics = Graphics.FromImage(SharpBMap)
' Draw text string to SharpGraf PictureBox
'
SharpGraf.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
SharpGraf.Clear(Color.White)
SharpGraf.DrawString(TxtStr, CurrFont, CurrBrush, 0, 0, CurrFormat)
' OutSharpGL is the Picture box to which the text string is sent
OutSharpGL.Image = SharpBMap
' Save the bitmap to disk: when the file is viewed, the image is Ok.
SharpBMap.Save(FilNameStr)
' Set the color
Gl.Color(1.0f, 1.0f, 1.0f)
' Set the Raster position
Gl.RasterPos(0, 0)
' Transfer the Bitmap
Gl.Bitmap(iWidth, iHeight, 0.0f, 0.0f, 0.0f, 0.0f, BitmapToByte(SharpBMap))
' Function to convert a Bitmap to a Byte() array
Friend Function BitmapToByte(ByRef Bmp As Bitmap) As Byte()
Dim converter As New ImageConverter()
Return DirectCast(converter.ConvertTo(Bmp, GetType(Byte())), Byte())
End Function