'*******************************************************************************
' Класс для загрузки изображений из байтового массива
' Накладыват интерфейсы IStream и IPicture на выделенную область памяти
'*******************************************************************************
Option Explicit
Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As GUID) As Long
Private Declare Function IsEqualGUID Lib "ole32" (rguid1 As GUID, rguid2 As GUID) As Boolean
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As CBoolean, ppstm As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As CBoolean, riid As GUID, ppvObj As Any) As Long
Private Const sIID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
Private Const S_OK = 0
Private Const GMEM_MOVEABLE = &H2
Private Enum CBoolean
CFalse = 0
CTrue = 1
End Enum
Private Type GUID
dwData1 As Long
wData2 As Integer
wData3 As Integer
abData4(7) As Byte
End Type
Public Function CreatePicture(abPic() As Byte) As IPicture
Dim nLow As Long
Dim cbMem As Long
Dim hMem As Long
Dim lpMem As Long
Dim IID_IPicture As GUID
Dim istm As stdole.IUnknown
Dim ipic As IPicture
' получаем размер картинки
On Error GoTo Out
nLow = LBound(abPic)
On Error GoTo 0
cbMem = (UBound(abPic) - nLow) + 1
' Выделяем память
hMem = GlobalAlloc(GMEM_MOVEABLE, cbMem)
If hMem Then
lpMem = GlobalLock(hMem)
If lpMem Then
'Копируем байты и разлочиваем область памяти
MoveMemory ByVal lpMem, abPic(nLow), cbMem
Call GlobalUnlock(hMem)
' Создаем интерфейст IStream
If (CreateStreamOnHGlobal(hMem, CTrue, istm) = S_OK) Then
If (CLSIDFromString(StrPtr(sIID_IPicture), IID_IPicture) = S_OK) Then
' Создаем интерфейс IPicture из IStream
Call OleLoadPicture(ByVal ObjPtr(istm), cbMem, CFalse, IID_IPicture, CreatePicture)
End If
End If
End If
End If
Out:
End Function
iDecompResult = DCI_DecompressImage(m_DataBlobCopy, m_DataBlob.Size,
m_DecompressedData, cDECOMPPICSIZE,
DCIStruct, &BmpInfoHdr);
DrawDibDraw(m_DDH, PaintBox->Canvas->Handle,
1, 1, PaintBox->Width-1, PaintBox->Height-1,
&BmpInfoHdr, m_DecompressedData,
0, 0, BmpInfoHdr.biWidth, BmpInfoHdr.biHeight,
0)
ANDLL писал(а):CHAR это 1 байт, это все поняли...
ANDLL писал(а):Другое дело что не очень ясно как
а) Узнать размер этого массива
ANDLL писал(а):б) Есть много способов хранить картинку на компьютере... Какой тут не очень ясно...
Сейчас этот форум просматривают: Google-бот, SemrushBot и гости: 97