помогите роздуплитса где то вообще не то что нада выбивает гдето вообще ничего вот например Planes должно быть 1 а оно мне выбивает 0.И как вообще загрузить картинку?Теорию я знаю а вот з практикой трдновото
Вот мой код
Public BITMAPFILEHEADER As BITMAPFILEHEADER
Public Struct As Struct
Type BITMAPFILEHEADER
Type As String * 2
Size As Long
Reserved1 As String * 2
Reserved2 As String * 2
OffBits As Long
End Type
Type Struct
Size As Long
Width As Long
Height As Long
Planes As Long
BitCount As Long
Compression As Long
SizeImage As Long
XPelsPerMeter As Long
YPelsPerMeter As Long
ClrUsed As Long
ClrImportant As Long
End Type
Type Image
RedMask As Byte
GreenMask As Byte
BlueMask As Byte
AlphaMask As Byte
CSType As Byte
'CIEXYZTRIPLE Endpoints;
GammaRed As Byte
GammaGreen As Byte
GammaBlue As Byte
End Type
Private Sub main()
Get_Struct "c:\docal.bmp"
End Sub
Public Function Get_BITMAPFILEHEADER(FileName As String)
Open FileName For Binary As #1
Get #1, 1, BITMAPFILEHEADER.Type
Get #1, 2, BITMAPFILEHEADER.Size
Get #1, 6, BITMAPFILEHEADER.Reserved1
Get #1, 8, BITMAPFILEHEADER.Reserved2
Get #1, 10, BITMAPFILEHEADER.OffBits
Close #1
End Function
Public Function Get_Struct(FileName As String)
Open FileName For Binary As #1
Get #1, 14, Struct.Size
Get #1, 18, Struct.Width
Get #1, 22, Struct.Height
Get #1, 26, Struct.Planes
Get #1, 28, Struct.BitCount
Get #1, 30, Struct.Compression
Get #1, 34, Struct.SizeImage
Get #1, 38, Struct.XPelsPerMeter
Get #1, 42, Struct.YPelsPerMeter
Get #1, 46, Struct.ClrUsed
Get #1, 50, Struct.ClrImportant
Close #1
Ща вспомнил, как я настойчиво и долго пытался заставить картинки загружаться)) с трудом нашел файлик
Private Declare Function SetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
'Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hfile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type BITMAPFILEHEADER '14 bytes
bfType As String * 2 '"magic cookie" - must be "BM"
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors() As Long 'array of RGBQUADs
End Type
Private Type paletteX
G As Byte
R As Byte
B As Byte
End Type
Public Function BMPFillInfoStruct(ByVal filename As String) As Boolean
Dim bmih As BITMAPINFOHEADER, palette As paletteX, hfile As Long, bfh As BITMAPFILEHEADER
Dim WritePos As Long
hfile = FreeFile()
On Error Resume Next
Open filename For Binary Access Read As #hfile
Get #hfile, , bfh
Get #hfile, 15, bmih 'start at the 15th byte
WritePos = 55
For yy = bmih.biHeight - 1 To 0 Step -1
For xx = 0 To bmih.biWidth - 1
Get #hfile, WritePos, palette
SetPixel Picture1.hdc, xx, yy, RGB(palette.R, palette.G, palette.B)
WritePos = WritePos + Len(palette)
Next xx
WritePos = X4(WritePos)
Picture1.Refresh
Next yy
Close #hfile 'Close file
BMPFillInfoStruct = True 'indicate success
End Function
Private Sub Command1_Click()
BMPFillInfoStruct "G:\Мои документы\Мои рисунки\VectorCell2DesktopWallpaper.bmp"
End Sub
Public Function X4(Number As Long) As Long
Do While Number Mod 4 <> 0
Number = Number + 1
Loop
X4 = Number
End Function
Private Sub Form_Resize()
Picture1.Width = ScaleWidth
Picture1.Height = ScaleHeight
End Sub
Видимо мне очень хотелось чтоб программа сама читала файл... Есть способ проще и во много раз быстрее - через SetDIBitsToDevice
Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type BITMAPFILEHEADER '14 bytes
bfType As String * 2 '"magic cookie" - must be "BM"
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors() As Long 'array of RGBQUADs
End Type
Public Function BMPFillInfoStruct(ByVal filename As String) As Boolean
Dim bmih As BITMAPINFOHEADER, hfile As Long, bfh As BITMAPFILEHEADER
Dim BMi As BITMAPINFO
Dim WritePos As Long
Dim FileDat() As Byte
hfile = FreeFile()
'On Error Resume Next
ReDim FileDat(FileLen(filename) - 54)
Open filename For Binary Access Read As #hfile
Get #hfile, , bfh
Get #hfile, 15, BMi.bmiHeader 'start at the 15th byte
Get #hfile, 55, FileDat
Close #hfile 'Close file
Call SetDIBitsToDevice(Picture1.hdc, 0, 0, BMi.bmiHeader.biWidth, BMi.bmiHeader.biHeight, 0, 0, 0, BMi.bmiHeader.biHeight, FileDat(0), BMi, 0)
Picture1.Refresh
BMPFillInfoStruct = True 'indicate success
End Function
p.s. кстати почему-то в первом примере без выравнивания (функ. X4) всё работает правильнее. Может оно и не нужно...
Винанд ты не прав твой код читает не все когда в бмп 256 цветов оно тупит картинку.На 32 битах оно тоже не будет работать так как там один цвет не три байта а 4