Вопрос таков: мне надо прочитать битмап из библиотеки файлов, т.е. из одного большого файла, при этом мне не нужно экстрактить этой файл.
Примерный план:
1)Загружаю в переменную бинарник файла
2)А дальше я не знаю!

Э... Че делать?
MSDN & API-Guide писал(а):CreateBitmap
The CreateBitmap function creates a bitmap with the specified width, height, and color format (color planes and bits per pixel).
· nWidth
Specifies the bitmap width, in pixels.
· nHeight
Specifies the bitmap height, in pixels.
· cPlanes
Specifies the number of color planes used by the device.
· cBitsPerPel
Specifies the number of bits required to identify the color of a single pixel.
· lpvBits
Points to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the new bitmap is undefined.
Amed писал(а):Надо же знать размер заголовка.
Public Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Public Type ColTable
rgbRed As Byte
rgbGreen As Byte
rgbBlue As Byte
rgbReserved As Byte
End Type
Public Type sBITMAP
bmfhSize As Long
bmfhOffsetBits As Long
bmihSize As Long
bmihWidth As Long
bmihHeight As Long
bmihPlanes As Integer
bmihBitCount As Integer
bmihCompression As Long
bmihSizeImage As Long
bmihXpelsPerMeter As Long
bmihYpelsPerMeter As Long
bmihColorsUsed As Long
bmihColorsImportant As Long
bmpColorTable(0 To 255) As ColTable
bmpImage() As Byte
End Type
Public Function LoadBitmap(FileName As String, StartByte As Long, FileLen As Long) As sBITMAP
Dim I As Long
Dim TmpBMP As sBITMAP
TmpBMP.bmfhSize = GetByte(FileName, StartByte + 2) + GetByte(FileName, StartByte + 3) * 256& + GetByte(FileName, StartByte + 4) * 256& ^ 2 + GetByte(FileName, StartByte + 5) * 256& ^ 3
TmpBMP.bmfhOffsetBits = GetByte(FileName, StartByte + 10) + GetByte(FileName, StartByte + 11) * 256& + GetByte(FileName, StartByte + 12) * 256& ^ 2 + GetByte(FileName, StartByte + 13) * 256& ^ 3
TmpBMP.bmihSize = GetByte(FileName, StartByte + 14) + GetByte(FileName, StartByte + 15) * 256& + GetByte(FileName, StartByte + 16) * 256& ^ 2 + GetByte(FileName, StartByte + 17) * 256& ^ 3
TmpBMP.bmihWidth = GetByte(FileName, StartByte + 18) + GetByte(FileName, StartByte + 19) * 256& + GetByte(FileName, StartByte + 20) * 256& ^ 2 + GetByte(FileName, StartByte + 21) * 256& ^ 3
TmpBMP.bmihHeight = GetByte(FileName, StartByte + 22) + GetByte(FileName, StartByte + 23) * 256& + GetByte(FileName, StartByte + 24) * 256& ^ 2 + GetByte(FileName, StartByte + 25) * 256& ^ 3
TmpBMP.bmihPlanes = GetByte(FileName, StartByte + 26) + GetByte(FileName, StartByte + 27)
TmpBMP.bmihBitCount = GetByte(FileName, StartByte + 28) + GetByte(FileName, StartByte + 29)
TmpBMP.bmihCompression = GetByte(FileName, StartByte + 30) + GetByte(FileName, StartByte + 31) * 256& + GetByte(FileName, StartByte + 32) * 256& ^ 2 + GetByte(FileName, StartByte + 33) * 256& ^ 3
TmpBMP.bmihSizeImage = GetByte(FileName, StartByte + 34) + GetByte(FileName, StartByte + 35) * 256& + GetByte(FileName, StartByte + 36) * 256& ^ 2 + GetByte(FileName, StartByte + 37) * 256& ^ 3
TmpBMP.bmihXpelsPerMeter = GetByte(FileName, StartByte + 38) + GetByte(FileName, StartByte + 39) * 256& + GetByte(FileName, StartByte + 40) * 256& ^ 2 + GetByte(FileName, StartByte + 41) * 256& ^ 3
TmpBMP.bmihYpelsPerMeter = GetByte(FileName, StartByte + 42) + GetByte(FileName, StartByte + 43) * 256& + GetByte(FileName, StartByte + 44) * 256& ^ 2 + GetByte(FileName, StartByte + 45) * 256& ^ 3
TmpBMP.bmihColorsUsed = GetByte(FileName, StartByte + 46) + GetByte(FileName, StartByte + 47) * 256& + GetByte(FileName, StartByte + 48) * 256& ^ 2 + GetByte(FileName, StartByte + 49) * 256& ^ 3
TmpBMP.bmihColorsImportant = GetByte(FileName, StartByte + 50) + GetByte(FileName, StartByte + 51) * 256& + GetByte(FileName, StartByte + 52) * 256& ^ 2 + GetByte(FileName, StartByte + 53) * 256& ^ 3
ReDim TmpBMP.bmpImage(0 To TmpBMP.bmihSizeImage - 1)
For I = 0 To 255
TmpBMP.bmpColorTable(I).rgbRed = GetByte(FileName, StartByte + 54 + I * 4 + 1)
TmpBMP.bmpColorTable(I).rgbGreen = GetByte(FileName, StartByte + 54 + I * 4 + 2)
TmpBMP.bmpColorTable(I).rgbBlue = GetByte(FileName, StartByte + 54 + I * 4 + 3)
TmpBMP.bmpColorTable(I).rgbReserved = GetByte(FileName, StartByte + 54 + I * 4 + 4)
Next I
For I = 0 To UBound(TmpBMP.bmpImage)
TmpBMP.bmpImage(I) = GetByte(FileName, StartByte + 54 + 1024 + I)
DoEvents
Next I
LoadBitmap = TmpBMP
End Function
Public Function GetByte(ByVal FileName As String, ByVal Address As Double) As Byte
On Error GoTo 1
Dim FN As Byte
Dim B As Byte
FN = FreeFile
Open FileName For Binary As FN
Get #FN, Address, GetByte
1: Close #FN
End Function
Public Function GetPicture(sPicture As sBITMAP) As Picture
Set GetPicture = CreateBitmap(sPicture.bmihWidth, sPicture.bmihHeight, sPicture.bmihPlanes, sPicture.bmihBitCount, VarPtr(sPicture.bmpImage))
End Function
Private Sub Form_Load()
Set Picture1.Picture = GetPicture(LoadBitmap("c:\4.bmp", 1, FileLen("c:\4.bmp")))
End Sub
Завтра посмотрю подробнее.
Сейчас этот форум просматривают: Yandex-бот и гости: 49