powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / .png и Visual Basic 6
22 сообщений из 22, страница 1 из 1
.png и Visual Basic 6
    #37327254
FedX
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Можно ли сделать так, чтобы VB6 читал .png файлы?
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327257
Фотография Shocker.Pro
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FedX,

Читать можно любой файл. Вопрос в конечной цели.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327268
FedX
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Shocker.Pro, я хочу чтобы VB6 загрузил картинку с png форматом, то есть чтобы она оказалась у меня на форме. В Image и PictureBox не получается, пишет "Invalid Picture"
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327275
Фотография Shocker.Pro
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Можно в Browser
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327293
FedX
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Shocker.Pro, мне надо чтобы картинка была прозрачной и часть объектов на заднем плане было видно. А webbrowser (надеюсь вы это имели в виду? если нет - простите, я новичок) она не прозрачная получается.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327406
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FedX,

Если нужна (полу)прозрачность в Image или PictureBox, то проще всего подсунуть им картинку в формате EMF или WMF.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327417
FedX
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Бенедикт, просто я имею много файлов с разрешением png и хотел без конвертации открыть их в VB6.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37327436
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
FedX,

это означает, что придётся писать процедуру, которая делает такую конвертацию на лету (средствами GDI+, например).
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37329368
Фотография Akina
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Если речь об одноразовой операции (файлы будут входить в состав приложения) - воспользуйтесь любым пакетным конвертором и переведите эти png в приемлемый формат.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37329591
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Многа букаф про перевод из битмапа с пиксельным форматом A8R8G8B8 в EMFOption Explicit

Private Enum BOOL
FALSE_BOOL
TRUE_BOOL
End Enum

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

Private Declare Function CLSIDFromString Lib "ole32" ( _
ByVal lpsz As Long, rguid As GUID) As Long
Private Const IIDSTR_IPictureDisp$ = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"

Private Enum PICTYPE
PICTYPE_UNINITIALIZED = -1
PICTYPE_NONE = 0
PICTYPE_BITMAP = 1
PICTYPE_METAFILE = 2
PICTYPE_ICON = 3
PICTYPE_ENHMETAFILE = 4
End Enum

Private Type PICTDESCEMF
cbSizeOfStruct As Long
PictType As PICTYPE
hEMF As Long
Reserved1 As Long
Reserved2 As Long
End Type

Private Declare Function OleCreatePictureIndirect Lib "olepro32" ( _
pPictDesc As Any, riid As GUID, _
ByVal fOwn As BOOL, ppvObj As IPictureDisp) As Long


Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" ( _
ByVal lpDriverName As String, ByVal lpDeviceName As String, _
ByVal lpOutput As String, lpInitData As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As BOOL

Private Declare Function SelectObject Lib "gdi32" ( _
ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" ( _
ByVal hObject As Long) As BOOL

Private Enum DeviceCapIndex
HORZSIZE = 4 ' Horizontal size in millimeters
VERTSIZE = 6 ' Vertical size in millimeters
HORZRES = 8 ' Horizontal width in pixels
VERTRES = 10 ' Vertical width in pixels
LOGPIXELSX = 88 ' Logical pixels/inch in X
LOGPIXELSY = 90 ' Logical pixels/inch in Y
End Enum
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As DeviceCapIndex) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function CreateEnhMetaFile Lib "gdi32" _
Alias "CreateEnhMetaFileA" ( _
ByVal hdcRef As Long, ByVal lpFileName As String, lpRect As RECT, _
ByVal lpDescription As String) As Long
Private Declare Function CloseEnhMetaFile Lib "gdi32" ( _
ByVal hDC As Long) As Long

Private Enum MapMode
MM_ANISOTROPIC = 8 ' Map mode anisotropic
End Enum
Private Declare Function SetMapMode Lib "gdi32" ( _
ByVal hDC As Long, ByVal nMapMode As MapMode) As MapMode

Private Declare Function SetWindowExtEx Lib "gdi32" ( _
ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, _
lpSize As Any) As BOOL
Private Declare Function SetViewportExtEx Lib "gdi32" ( _
ByVal hDC As Long, ByVal nX As Long, _
ByVal nY As Long, lpSize As Any) As BOOL


Private Type BLENDFUNCTION
BlendOp As Byte
BlendFlags As Byte
SourceConstantAlpha As Byte
AlphaFormat As Byte
End Type
Private Type BLENDFUNCTIONBYVAL
Value As Long
End Type
Private Const AC_SRC_OVER = &H0
'Alpha format flags
Private Const AC_SRC_ALPHA = &H1
'Private Const AC_SRC_NO_PREMULT_ALPHA = &H1
'Private Const AC_SRC_NO_ALPHA = &H2
'Private Const AC_DST_NO_PREMULT_ALPHA = &H10
'Private Const AC_DST_NO_ALPHA = &H20

Private Declare Function AlphaBlend Lib "msimg32" ( _
ByVal hdcDest As Long, _
ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, _
ByVal nWidthDest As Long, ByVal nHeightDest As Long, _
ByVal hdcSrc As Long, _
ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, _
ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, _
ByVal lBlendFunction As Long) As BOOL


Private Enum GpStatus 'GDI+ Status
OK = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
ProfileNotFound = 21
End Enum

Private Enum GdiplusVersion
Ver1 = 1
End Enum

Private Type GdiplusStartupInput
GdiplusVersion As GdiplusVersion
DebugEventCallback As Long
SuppressBackgroundThread As BOOL
SuppressExternalCodecs As BOOL
End Type

Private Declare Function GdiplusStartup Lib "gdiplus" ( _
lToken As Long, lpInput As GdiplusStartupInput, _
Optional ByRef lpOutput As Any) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" ( _
ByVal lToken As Long) As GpStatus

Private Declare Function GdipCreateBitmapFromFile Lib "gdiplus" ( _
ByVal wszFileName As Long, nBitmap As Long) As GpStatus
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "gdiplus" ( _
ByVal nBitmap As Long, hbmReturn As Long, _
ByVal argbBackground As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" ( _
ByVal nImage As Long) As GpStatus

Public Enum PixelFormat
PixelFormatUndefined = &H0&
PixelFormatDontCare = PixelFormatUndefined
PixelFormatMax = &HF&
PixelFormat1_8 = &H100&
PixelFormat4_8 = &H400&
PixelFormat8_8 = &H800&
PixelFormat16_8 = &H1000&
PixelFormat24_8 = &H1800&
PixelFormat32_8 = &H2000&
PixelFormat48_8 = &H3000&
PixelFormat64_8 = &H4000&
PixelFormat16bppRGB555 = &H21005
PixelFormat16bppRGB565 = &H21006
PixelFormat16bppGrayScale = &H101004
PixelFormat16bppARGB1555 = &H61007
PixelFormat24bppRGB = &H21808
PixelFormat32bppRGB = &H22009
PixelFormat32bppARGB = &H26200A
PixelFormat32bppPARGB = &HD200B
PixelFormat48bppRGB = &H10300C
PixelFormat64bppARGB = &H34400D
PixelFormat64bppPARGB = &H1C400E
PixelFormatGDI = &H20000
PixelFormat1bppIndexed = &H30101
PixelFormat4bppIndexed = &H30402
PixelFormat8bppIndexed = &H30803
PixelFormatAlpha = &H40000
PixelFormatIndexed = &H10000
PixelFormatPAlpha = &H80000
PixelFormatExtended = &H100000
PixelFormatCanonical = &H200000
End Enum
Private Declare Function GdipGetImagePixelFormat Lib "gdiplus" ( _
ByVal nImage As Long, ImagePixFmt As PixelFormat) As GpStatus
Private Declare Function GdipGetImageWidth Lib "gdiplus" ( _
ByVal nImage As Long, Width As Long) As GpStatus
Private Declare Function GdipGetImageHeight Lib "gdiplus" ( _
ByVal nImage As Long, Height As Long) As GpStatus

Private Function GdiErrorString(ByVal lError As GpStatus) As String
Select Case lError
Case GenericError: GdiErrorString = "Generic error"
Case InvalidParameter: GdiErrorString = "Invalid parameter"
Case OutOfMemory: GdiErrorString = "Out of memory"
Case ObjectBusy: GdiErrorString = "Object busy"
Case InsufficientBuffer: GdiErrorString = "Insufficient buffer"
Case NotImplemented: GdiErrorString = "Not implemented"
Case Win32Error: GdiErrorString = "Win32 error"
Case WrongState: GdiErrorString = "Wrong state"
Case Aborted: GdiErrorString = "Aborted"
Case FileNotFound: GdiErrorString = "File not found"
Case ValueOverflow: GdiErrorString = "Value overflow"
Case AccessDenied: GdiErrorString = "Access denied"
Case UnknownImageFormat: GdiErrorString = "Unknown image format"
Case FontFamilyNotFound: GdiErrorString = "Font family not found"
Case FontStyleNotFound: GdiErrorString = "Font style not found"
Case NotTrueTypeFont: GdiErrorString = "Not TrueType font"
Case UnsupportedGdiplusVersion: GdiErrorString = "Unsupported GDI+ version"
Case GdiplusNotInitialized: GdiErrorString = "GDI+ not initialized"
Case PropertyNotFound: GdiErrorString = "Property not found"
Case PropertyNotSupported: GdiErrorString = "Property not supported"
Case Else: GdiErrorString = "Unknown GDI+ error"
End Select
End Function

Private Function GdipExec(ByVal lStatus As GpStatus) As GpStatus
If lStatus <> OK Then MsgBox GdiErrorString(lStatus), vbExclamation, _
"GDI+ Error"
GdipExec = lStatus
End Function


Public Function LoadARGBBmpAsEmfPicture( _
ByVal FileName As String, _
Optional ByVal bAlpha As Byte = 255, _
Optional ByVal EMFFileName As String = vbNullString) As IPictureDisp
Dim GdipToken As Long
Dim si As GdiplusStartupInput
Dim nBitmap As Long
Dim hBitmap As Long
Dim pfPixFmt As PixelFormat
Dim cxWidth As Long, cyHeight As Long
Dim hicRef As Long
Dim iWidthMM As Long
Dim iHeightMM As Long
Dim iWidthPels As Long
Dim iHeightPels As Long
Dim iDPIX As Long
Dim iDPIY As Long
Dim rc As RECT
Dim hdcMeta As Long
Dim iWEX As Long, iWEY As Long
Dim iVEX As Long, iVEY As Long
Dim iGCD As Long
Dim hdcMem As Long
Dim hbmpOld As Long
Dim hEMF As Long
Dim bfBlend As BLENDFUNCTION
Dim bfvBlend As BLENDFUNCTIONBYVAL

si.GdiplusVersion = Ver1
GdipExec GdiplusStartup(GdipToken, si, ByVal 0&)
If GdipToken = 0 Then Exit Function
GdipExec GdipCreateBitmapFromFile(StrPtr(FileName), nBitmap)
If nBitmap Then
GdipExec GdipGetImagePixelFormat(nBitmap, pfPixFmt)
If pfPixFmt = PixelFormat32bppARGB Then
GdipExec GdipGetImageWidth(nBitmap, cxWidth)
GdipExec GdipGetImageHeight(nBitmap, cyHeight)
GdipExec GdipCreateHBITMAPFromBitmap(nBitmap, hBitmap, &H0)
Else
MsgBox "Wrong image format!", vbExclamation
End If
GdipExec GdipDisposeImage(nBitmap): nBitmap = 0
End If
GdipExec GdiplusShutdown(GdipToken): GdipToken = 0
If hBitmap = 0 Then Exit Function

hicRef = CreateIC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
iWidthMM = GetDeviceCaps(hicRef, HORZSIZE)
iHeightMM = GetDeviceCaps(hicRef, VERTSIZE)
iWidthPels = GetDeviceCaps(hicRef, HORZRES)
iHeightPels = GetDeviceCaps(hicRef, VERTRES)
iDPIX = GetDeviceCaps(hicRef, LOGPIXELSX)
iDPIY = GetDeviceCaps(hicRef, LOGPIXELSY)

'Размеры в сотых долях миллиметра
rc.Right = Int(cxWidth * 2540 / iDPIX + 0.5)
rc.Bottom = Int(cyHeight * 2540 / iDPIY + 0.5)

'Создаём "усовершенствованный" метафайл в памяти и на диске, если дано имя
hdcMeta = CreateEnhMetaFile(hicRef, EMFFileName, rc, vbNullString)

iWEX = cxWidth * iWidthMM * iDPIX * 10
iWEY = cyHeight * iHeightMM * iDPIY * 10
iVEX = cxWidth * iWidthPels * 254
iVEY = cyHeight * iHeightPels * 254
iGCD = GCD(GCD(GCD(iWEX, iWEY), iVEX), iVEY)
SetMapMode hdcMeta, MM_ANISOTROPIC
SetWindowExtEx hdcMeta, iWEX \ iGCD, iWEY \ iGCD, ByVal 0&
SetViewportExtEx hdcMeta, iVEX \ iGCD, iVEY \ iGCD, ByVal 0&

hdcMem = CreateCompatibleDC(hicRef)
DeleteDC hicRef: hicRef = 0
hbmpOld = SelectObject(hdcMem, hBitmap)

bfBlend.BlendOp = AC_SRC_OVER
bfBlend.BlendFlags = 0
bfBlend.SourceConstantAlpha = bAlpha
bfBlend.AlphaFormat = AC_SRC_ALPHA
LSet bfvBlend = bfBlend
AlphaBlend hdcMeta, 0, 0, cxWidth, cyHeight, _
hdcMem, 0, 0, cxWidth, cyHeight, bfvBlend.Value

SelectObject hdcMem, hbmpOld: hbmpOld = 0
DeleteDC hdcMem: hdcMem = 0
DeleteObject hBitmap: hBitmap = 0

hEMF = CloseEnhMetaFile(hdcMeta): hdcMeta = 0
Set LoadARGBBmpAsEmfPicture = CreateIPictureDispFromHENHMETAFILE(hEMF)
End Function


Public Function CreateIPictureDispFromHENHMETAFILE( _
ByVal hEMF As Long, _
Optional ByVal bPictureOwnsHandle As Boolean = True) As IPictureDisp
Dim IID_IPictureDisp As GUID
Dim PictDesc As PICTDESCEMF
With PictDesc
.cbSizeOfStruct = Len(PictDesc)
.PictType = PICTYPE_ENHMETAFILE
.hEMF = hEMF
End With
CLSIDFromString StrPtr(IIDSTR_IPictureDisp), IID_IPictureDisp
OleCreatePictureIndirect PictDesc, IID_IPictureDisp, -bPictureOwnsHandle, _
CreateIPictureDispFromHENHMETAFILE
End Function


Public Function GCD(ByVal a As Long, ByVal b As Long) As Long
Do While (a <> 0) And (b <> 0)
If a >= b Then a = a Mod b Else b = b Mod a
Loop
GCD = a + b
End Function
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37329595
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
не, лучше так
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
Option Explicit

Private Enum BOOL
   FALSE_BOOL
   TRUE_BOOL
End Enum

Private Type GUID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4( 0  To  7 ) As Byte
End Type

Private Declare Function CLSIDFromString Lib "ole32" ( _
   ByVal lpsz As Long, rguid As GUID) As Long
Private Const IIDSTR_IPictureDisp$ = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"

Private Enum PICTYPE
   PICTYPE_UNINITIALIZED = - 1 
   PICTYPE_NONE =  0 
   PICTYPE_BITMAP =  1 
   PICTYPE_METAFILE =  2 
   PICTYPE_ICON =  3 
   PICTYPE_ENHMETAFILE =  4 
End Enum

Private Type PICTDESCEMF
   cbSizeOfStruct As Long
   PictType As PICTYPE
   hEMF As Long
   Reserved1 As Long
   Reserved2 As Long
End Type

Private Declare Function OleCreatePictureIndirect Lib "olepro32" ( _
   pPictDesc As Any, riid As GUID, _
   ByVal fOwn As BOOL, ppvObj As IPictureDisp) As Long


Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" ( _
   ByVal lpDriverName As String, ByVal lpDeviceName As String, _
   ByVal lpOutput As String, lpInitData As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
   ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As BOOL

Private Declare Function SelectObject Lib "gdi32" ( _
   ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" ( _
   ByVal hObject As Long) As BOOL

Private Enum DeviceCapIndex
   HORZSIZE =  4            '  Horizontal size in millimeters
   VERTSIZE =  6            '  Vertical size in millimeters
   HORZRES =  8             '  Horizontal width in pixels
   VERTRES =  10            '  Vertical width in pixels
   LOGPIXELSX =  88         '  Logical pixels/inch in X
   LOGPIXELSY =  90         '  Logical pixels/inch in Y
End Enum
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nIndex As DeviceCapIndex) As Long

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Declare Function CreateEnhMetaFile Lib "gdi32" _
   Alias "CreateEnhMetaFileA" ( _
   ByVal hdcRef As Long, ByVal lpFileName As String, lpRect As RECT, _
   ByVal lpDescription As String) As Long
Private Declare Function CloseEnhMetaFile Lib "gdi32" ( _
   ByVal hDC As Long) As Long

Private Enum MapMode
   MM_ANISOTROPIC =  8  ' Map mode anisotropic
End Enum
Private Declare Function SetMapMode Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nMapMode As MapMode) As MapMode

Private Declare Function SetWindowExtEx Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, _
   lpSize As Any) As BOOL
Private Declare Function SetViewportExtEx Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nX As Long, _
   ByVal nY As Long, lpSize As Any) As BOOL


Private Type BLENDFUNCTION
   BlendOp As Byte
   BlendFlags As Byte
   SourceConstantAlpha As Byte
   AlphaFormat As Byte
End Type
Private Type BLENDFUNCTIONBYVAL
   Value As Long
End Type
Private Const AC_SRC_OVER = &H0
'Alpha format flags
Private Const AC_SRC_ALPHA = &H1
'Private Const AC_SRC_NO_PREMULT_ALPHA = &H1
'Private Const AC_SRC_NO_ALPHA = &H2
'Private Const AC_DST_NO_PREMULT_ALPHA = &H10
'Private Const AC_DST_NO_ALPHA = &H20

Private Declare Function AlphaBlend Lib "msimg32" ( _
  ByVal hdcDest As Long, _
  ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, _
  ByVal nWidthDest As Long, ByVal nHeightDest As Long, _
  ByVal hdcSrc As Long, _
  ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, _
  ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, _
  ByVal lBlendFunction As Long) As BOOL


Private Enum GpStatus 'GDI+ Status
   OK =  0 
   GenericError =  1 
   InvalidParameter =  2 
   OutOfMemory =  3 
   ObjectBusy =  4 
   InsufficientBuffer =  5 
   NotImplemented =  6 
   Win32Error =  7 
   WrongState =  8 
   Aborted =  9 
   FileNotFound =  10 
   ValueOverflow =  11 
   AccessDenied =  12 
   UnknownImageFormat =  13 
   FontFamilyNotFound =  14 
   FontStyleNotFound =  15 
   NotTrueTypeFont =  16 
   UnsupportedGdiplusVersion =  17 
   GdiplusNotInitialized =  18 
   PropertyNotFound =  19 
   PropertyNotSupported =  20 
   ProfileNotFound =  21 
End Enum

Private Enum GdiplusVersion
   Ver1 =  1 
End Enum

Private Type GdiplusStartupInput
   GdiplusVersion As GdiplusVersion
   DebugEventCallback As Long
   SuppressBackgroundThread As BOOL
   SuppressExternalCodecs As BOOL
End Type

Private Declare Function GdiplusStartup Lib "gdiplus" ( _
   lToken As Long, lpInput As GdiplusStartupInput, _
   Optional ByRef lpOutput As Any) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" ( _
   ByVal lToken As Long) As GpStatus

Private Declare Function GdipCreateBitmapFromFile Lib "gdiplus" ( _
   ByVal wszFileName As Long, nBitmap As Long) As GpStatus
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "gdiplus" ( _
   ByVal nBitmap As Long, hbmReturn As Long, _
   ByVal argbBackground As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" ( _
   ByVal nImage As Long) As GpStatus

Public Enum PixelFormat
   PixelFormatUndefined = &H0&
   PixelFormatDontCare = PixelFormatUndefined
   PixelFormatMax = &HF&
   PixelFormat1_8 = &H100&
   PixelFormat4_8 = &H400&
   PixelFormat8_8 = &H800&
   PixelFormat16_8 = &H1000&
   PixelFormat24_8 = &H1800&
   PixelFormat32_8 = &H2000&
   PixelFormat48_8 = &H3000&
   PixelFormat64_8 = &H4000&
   PixelFormat16bppRGB555 = &H21005
   PixelFormat16bppRGB565 = &H21006
   PixelFormat16bppGrayScale = &H101004
   PixelFormat16bppARGB1555 = &H61007
   PixelFormat24bppRGB = &H21808
   PixelFormat32bppRGB = &H22009
   PixelFormat32bppARGB = &H26200A
   PixelFormat32bppPARGB = &HD200B
   PixelFormat48bppRGB = &H10300C
   PixelFormat64bppARGB = &H34400D
   PixelFormat64bppPARGB = &H1C400E
   PixelFormatGDI = &H20000
   PixelFormat1bppIndexed = &H30101
   PixelFormat4bppIndexed = &H30402
   PixelFormat8bppIndexed = &H30803
   PixelFormatAlpha = &H40000
   PixelFormatIndexed = &H10000
   PixelFormatPAlpha = &H80000
   PixelFormatExtended = &H100000
   PixelFormatCanonical = &H200000
End Enum
Private Declare Function GdipGetImagePixelFormat Lib "gdiplus" ( _
   ByVal nImage As Long, ImagePixFmt As PixelFormat) As GpStatus
Private Declare Function GdipGetImageWidth Lib "gdiplus" ( _
   ByVal nImage As Long, Width As Long) As GpStatus
Private Declare Function GdipGetImageHeight Lib "gdiplus" ( _
   ByVal nImage As Long, Height As Long) As GpStatus

Private Function GdiErrorString(ByVal lError As GpStatus) As String
 Select Case lError
 Case GenericError:              GdiErrorString = "Generic error"
 Case InvalidParameter:          GdiErrorString = "Invalid parameter"
 Case OutOfMemory:               GdiErrorString = "Out of memory"
 Case ObjectBusy:                GdiErrorString = "Object busy"
 Case InsufficientBuffer:        GdiErrorString = "Insufficient buffer"
 Case NotImplemented:            GdiErrorString = "Not implemented"
 Case Win32Error:                GdiErrorString = "Win32 error"
 Case WrongState:                GdiErrorString = "Wrong state"
 Case Aborted:                   GdiErrorString = "Aborted"
 Case FileNotFound:              GdiErrorString = "File not found"
 Case ValueOverflow:             GdiErrorString = "Value overflow"
 Case AccessDenied:              GdiErrorString = "Access denied"
 Case UnknownImageFormat:        GdiErrorString = "Unknown image format"
 Case FontFamilyNotFound:        GdiErrorString = "Font family not found"
 Case FontStyleNotFound:         GdiErrorString = "Font style not found"
 Case NotTrueTypeFont:           GdiErrorString = "Not TrueType font"
 Case UnsupportedGdiplusVersion: GdiErrorString = "Unsupported GDI+ version"
 Case GdiplusNotInitialized:     GdiErrorString = "GDI+ not initialized"
 Case PropertyNotFound:          GdiErrorString = "Property not found"
 Case PropertyNotSupported:      GdiErrorString = "Property not supported"
 Case Else:                      GdiErrorString = "Unknown GDI+ error"
 End Select
End Function

Private Function GdipExec(ByVal lStatus As GpStatus) As GpStatus
 If lStatus <> OK Then MsgBox GdiErrorString(lStatus), vbExclamation, _
                              "GDI+ Error"
 GdipExec = lStatus
End Function


Public Function LoadARGBBmpAsEmfPicture( _
   ByVal FileName As String, _
   Optional ByVal bAlpha As Byte =  255 , _
   Optional ByVal EMFFileName As String = vbNullString) As IPictureDisp
 Dim GdipToken As Long
 Dim si As GdiplusStartupInput
 Dim nBitmap As Long
 Dim hBitmap As Long
 Dim pfPixFmt As PixelFormat
 Dim cxWidth As Long, cyHeight As Long
 Dim hicRef As Long
 Dim iWidthMM As Long
 Dim iHeightMM As Long
 Dim iWidthPels As Long
 Dim iHeightPels As Long
 Dim iDPIX As Long
 Dim iDPIY As Long
 Dim rc As RECT
 Dim hdcMeta As Long
 Dim iWEX As Long, iWEY As Long
 Dim iVEX As Long, iVEY As Long
 Dim iGCD As Long
 Dim hdcMem As Long
 Dim hbmpOld As Long
 Dim hEMF As Long
 Dim bfBlend As BLENDFUNCTION
 Dim bfvBlend As BLENDFUNCTIONBYVAL

 si.GdiplusVersion = Ver1
 GdipExec GdiplusStartup(GdipToken, si, ByVal  0 &)
 If GdipToken =  0  Then Exit Function
 GdipExec GdipCreateBitmapFromFile(StrPtr(FileName), nBitmap)
 If nBitmap Then
    GdipExec GdipGetImagePixelFormat(nBitmap, pfPixFmt)
    If pfPixFmt = PixelFormat32bppARGB Then
       GdipExec GdipGetImageWidth(nBitmap, cxWidth)
       GdipExec GdipGetImageHeight(nBitmap, cyHeight)
       GdipExec GdipCreateHBITMAPFromBitmap(nBitmap, hBitmap, &H0)
    Else
       MsgBox "Wrong image format!", vbExclamation
    End If
    GdipExec GdipDisposeImage(nBitmap): nBitmap =  0 
 End If
 GdipExec GdiplusShutdown(GdipToken): GdipToken =  0 
 If hBitmap =  0  Then Exit Function
 
 hicRef = CreateIC("DISPLAY", vbNullString, vbNullString, ByVal  0 &)
 iWidthMM = GetDeviceCaps(hicRef, HORZSIZE)
 iHeightMM = GetDeviceCaps(hicRef, VERTSIZE)
 iWidthPels = GetDeviceCaps(hicRef, HORZRES)
 iHeightPels = GetDeviceCaps(hicRef, VERTRES)
 iDPIX = GetDeviceCaps(hicRef, LOGPIXELSX)
 iDPIY = GetDeviceCaps(hicRef, LOGPIXELSY)
 
 'Размеры в сотых долях миллиметра
 rc.Right = Int(cxWidth *  2540  / iDPIX +  0 . 5 )
 rc.Bottom = Int(cyHeight *  2540  / iDPIY +  0 . 5 )
 
 'Создаём "усовершенствованный" метафайл в памяти и на диске, если дано имя
 hdcMeta = CreateEnhMetaFile(hicRef, EMFFileName, rc, vbNullString)
 
 iWEX = cxWidth * iWidthMM * iDPIX *  10 
 iWEY = cyHeight * iHeightMM * iDPIY *  10 
 iVEX = cxWidth * iWidthPels *  254 
 iVEY = cyHeight * iHeightPels *  254 
 iGCD = GCD(GCD(GCD(iWEX, iWEY), iVEX), iVEY)
 SetMapMode hdcMeta, MM_ANISOTROPIC
 SetWindowExtEx hdcMeta, iWEX \ iGCD, iWEY \ iGCD, ByVal  0 &
 SetViewportExtEx hdcMeta, iVEX \ iGCD, iVEY \ iGCD, ByVal  0 &
 
 hdcMem = CreateCompatibleDC(hicRef)
 DeleteDC hicRef: hicRef =  0 
 hbmpOld = SelectObject(hdcMem, hBitmap)

 bfBlend.BlendOp = AC_SRC_OVER
 bfBlend.BlendFlags =  0 
 bfBlend.SourceConstantAlpha = bAlpha
 bfBlend.AlphaFormat = AC_SRC_ALPHA
 LSet bfvBlend = bfBlend
 AlphaBlend hdcMeta,  0 ,  0 , cxWidth, cyHeight, _
            hdcMem,  0 ,  0 , cxWidth, cyHeight, bfvBlend.Value

 SelectObject hdcMem, hbmpOld: hbmpOld =  0 
 DeleteDC hdcMem: hdcMem =  0 
 DeleteObject hBitmap: hBitmap =  0 
    
 hEMF = CloseEnhMetaFile(hdcMeta): hdcMeta =  0 
 Set LoadARGBBmpAsEmfPicture = CreateIPictureDispFromHENHMETAFILE(hEMF)
End Function


Public Function CreateIPictureDispFromHENHMETAFILE( _
   ByVal hEMF As Long, _
   Optional ByVal bPictureOwnsHandle As Boolean = True) As IPictureDisp
 Dim IID_IPictureDisp As GUID
 Dim PictDesc As PICTDESCEMF
 With PictDesc
    .cbSizeOfStruct = Len(PictDesc)
    .PictType = PICTYPE_ENHMETAFILE
    .hEMF = hEMF
 End With
 CLSIDFromString StrPtr(IIDSTR_IPictureDisp), IID_IPictureDisp
 OleCreatePictureIndirect PictDesc, IID_IPictureDisp, -bPictureOwnsHandle, _
                          CreateIPictureDispFromHENHMETAFILE
End Function


Public Function GCD(ByVal a As Long, ByVal b As Long) As Long
 Do While (a <>  0 ) And (b <>  0 )
    If a >= b Then a = a Mod b Else b = b Mod a
 Loop
 GCD = a + b
End Function
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637107
vital24
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Бенедикт,
Функция GdipCreateHBITMAPFromBitmap, вызывает ошибку 8: Not enough storage is available to process this command.
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
...
If nBitmap Then
    GdipExec GdipGetImagePixelFormat(nBitmap, pfPixFmt)
    If pfPixFmt = PixelFormat32bppARGB Then
       GdipExec GdipGetImageWidth(nBitmap, cxWidth)
       GdipExec GdipGetImageHeight(nBitmap, cyHeight)
       GdipExec GdipCreateHBITMAPFromBitmap(nBitmap, hBitmap, &H0)

       Debug.Print Err.LastDllError

    Else
       MsgBox "Wrong image format!", vbExclamation
    End If
    GdipExec GdipDisposeImage(nBitmap): nBitmap = 0
 End If
...


Аргумент функции LoadARGBBmpAsEmfPicture FileName - любой png-файл. Пробовал на 2 компютерах - результат тот же.
Хотя результат функции LoadARGBBmpAsEmfPicture отрабатывает правильно.
Функцию GdipCreateHBITMAPFromBitmap также использовал в других местах программы, выдает ту же ошибку 8. Что может быть?
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637221
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
vital24,

Тестировал с изображениями размером 2048*1536, формат пикселя 32 бит ARGB, на Windows XP - без проблем. Функция под этот формат пикселя и написана, собственно.
Каковы свойства ваших тестовых изображений? Можете предоставить образец?

Не понял фразы "Хотя результат функции LoadARGBBmpAsEmfPicture отрабатывает правильно".
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637258
vital24
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Бенедикт,

Вложил mdb и два файла png. На обоих ошибка 8.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637354
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
vital24,

А, это просто отладочный вывод, даже не помню, зачем. Можно убрать, чтобы не смущал. Сама функция отрабатывает нормально. Если интересует применение именно в Access-е, то см. вложение.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637390
vital24
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Бенедикт,

этот просто отладочный вывод написал я. У вас выводит этот код ошибки (8)?
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #37637460
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
vital24этот просто отладочный вывод написал я.Да, действительно, не моё туфля.vital24У вас выводит этот код ошибки (8)?Да, выводит. Но о чём говорит Err.LastDllError в данном случае? Ни о чём. Функции GDI+ используют свои коды ошибок, не пересекающиеся с кодами ошибок WinAPI, и возвращают их явно. Что с того, что функция GDI+ (GdipCreateHBITMAPFromBitmap) внутри себя вызвала (предположительно) какую-то функцию WinAPI, которая выполнила SetLastError(8)? Главное, что GdipCreateHBITMAPFromBitmap вернула свой код результата выполнения ("успех"), ориентироваться надо на него.
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
.png и Visual Basic 6
    #38806728
Eolt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Бенедикт+
не, лучше так
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
Option Explicit

Private Enum BOOL
   FALSE_BOOL
   TRUE_BOOL
End Enum

Private Type GUID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(0 To 7) As Byte
End Type

Private Declare Function CLSIDFromString Lib "ole32" ( _
   ByVal lpsz As Long, rguid As GUID) As Long
Private Const IIDSTR_IPictureDisp$ = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"

Private Enum PICTYPE
   PICTYPE_UNINITIALIZED = -1
   PICTYPE_NONE = 0
   PICTYPE_BITMAP = 1
   PICTYPE_METAFILE = 2
   PICTYPE_ICON = 3
   PICTYPE_ENHMETAFILE = 4
End Enum

Private Type PICTDESCEMF
   cbSizeOfStruct As Long
   PictType As PICTYPE
   hEMF As Long
   Reserved1 As Long
   Reserved2 As Long
End Type

Private Declare Function OleCreatePictureIndirect Lib "olepro32" ( _
   pPictDesc As Any, riid As GUID, _
   ByVal fOwn As BOOL, ppvObj As IPictureDisp) As Long


Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" ( _
   ByVal lpDriverName As String, ByVal lpDeviceName As String, _
   ByVal lpOutput As String, lpInitData As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
   ByVal hDC As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As BOOL

Private Declare Function SelectObject Lib "gdi32" ( _
   ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" ( _
   ByVal hObject As Long) As BOOL

Private Enum DeviceCapIndex
   HORZSIZE = 4           '  Horizontal size in millimeters
   VERTSIZE = 6           '  Vertical size in millimeters
   HORZRES = 8            '  Horizontal width in pixels
   VERTRES = 10           '  Vertical width in pixels
   LOGPIXELSX = 88        '  Logical pixels/inch in X
   LOGPIXELSY = 90        '  Logical pixels/inch in Y
End Enum
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nIndex As DeviceCapIndex) As Long

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Declare Function CreateEnhMetaFile Lib "gdi32" _
   Alias "CreateEnhMetaFileA" ( _
   ByVal hdcRef As Long, ByVal lpFileName As String, lpRect As RECT, _
   ByVal lpDescription As String) As Long
Private Declare Function CloseEnhMetaFile Lib "gdi32" ( _
   ByVal hDC As Long) As Long

Private Enum MapMode
   MM_ANISOTROPIC = 8 ' Map mode anisotropic
End Enum
Private Declare Function SetMapMode Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nMapMode As MapMode) As MapMode

Private Declare Function SetWindowExtEx Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, _
   lpSize As Any) As BOOL
Private Declare Function SetViewportExtEx Lib "gdi32" ( _
   ByVal hDC As Long, ByVal nX As Long, _
   ByVal nY As Long, lpSize As Any) As BOOL


Private Type BLENDFUNCTION
   BlendOp As Byte
   BlendFlags As Byte
   SourceConstantAlpha As Byte
   AlphaFormat As Byte
End Type
Private Type BLENDFUNCTIONBYVAL
   Value As Long
End Type
Private Const AC_SRC_OVER = &H0
'Alpha format flags
Private Const AC_SRC_ALPHA = &H1
'Private Const AC_SRC_NO_PREMULT_ALPHA = &H1
'Private Const AC_SRC_NO_ALPHA = &H2
'Private Const AC_DST_NO_PREMULT_ALPHA = &H10
'Private Const AC_DST_NO_ALPHA = &H20

Private Declare Function AlphaBlend Lib "msimg32" ( _
  ByVal hdcDest As Long, _
  ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, _
  ByVal nWidthDest As Long, ByVal nHeightDest As Long, _
  ByVal hdcSrc As Long, _
  ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, _
  ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, _
  ByVal lBlendFunction As Long) As BOOL


Private Enum GpStatus 'GDI+ Status
   OK = 0
   GenericError = 1
   InvalidParameter = 2
   OutOfMemory = 3
   ObjectBusy = 4
   InsufficientBuffer = 5
   NotImplemented = 6
   Win32Error = 7
   WrongState = 8
   Aborted = 9
   FileNotFound = 10
   ValueOverflow = 11
   AccessDenied = 12
   UnknownImageFormat = 13
   FontFamilyNotFound = 14
   FontStyleNotFound = 15
   NotTrueTypeFont = 16
   UnsupportedGdiplusVersion = 17
   GdiplusNotInitialized = 18
   PropertyNotFound = 19
   PropertyNotSupported = 20
   ProfileNotFound = 21
End Enum

Private Enum GdiplusVersion
   Ver1 = 1
End Enum

Private Type GdiplusStartupInput
   GdiplusVersion As GdiplusVersion
   DebugEventCallback As Long
   SuppressBackgroundThread As BOOL
   SuppressExternalCodecs As BOOL
End Type

Private Declare Function GdiplusStartup Lib "gdiplus" ( _
   lToken As Long, lpInput As GdiplusStartupInput, _
   Optional ByRef lpOutput As Any) As GpStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" ( _
   ByVal lToken As Long) As GpStatus

Private Declare Function GdipCreateBitmapFromFile Lib "gdiplus" ( _
   ByVal wszFileName As Long, nBitmap As Long) As GpStatus
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "gdiplus" ( _
   ByVal nBitmap As Long, hbmReturn As Long, _
   ByVal argbBackground As Long) As GpStatus
Private Declare Function GdipDisposeImage Lib "gdiplus" ( _
   ByVal nImage As Long) As GpStatus

Public Enum PixelFormat
   PixelFormatUndefined = &H0&
   PixelFormatDontCare = PixelFormatUndefined
   PixelFormatMax = &HF&
   PixelFormat1_8 = &H100&
   PixelFormat4_8 = &H400&
   PixelFormat8_8 = &H800&
   PixelFormat16_8 = &H1000&
   PixelFormat24_8 = &H1800&
   PixelFormat32_8 = &H2000&
   PixelFormat48_8 = &H3000&
   PixelFormat64_8 = &H4000&
   PixelFormat16bppRGB555 = &H21005
   PixelFormat16bppRGB565 = &H21006
   PixelFormat16bppGrayScale = &H101004
   PixelFormat16bppARGB1555 = &H61007
   PixelFormat24bppRGB = &H21808
   PixelFormat32bppRGB = &H22009
   PixelFormat32bppARGB = &H26200A
   PixelFormat32bppPARGB = &HD200B
   PixelFormat48bppRGB = &H10300C
   PixelFormat64bppARGB = &H34400D
   PixelFormat64bppPARGB = &H1C400E
   PixelFormatGDI = &H20000
   PixelFormat1bppIndexed = &H30101
   PixelFormat4bppIndexed = &H30402
   PixelFormat8bppIndexed = &H30803
   PixelFormatAlpha = &H40000
   PixelFormatIndexed = &H10000
   PixelFormatPAlpha = &H80000
   PixelFormatExtended = &H100000
   PixelFormatCanonical = &H200000
End Enum
Private Declare Function GdipGetImagePixelFormat Lib "gdiplus" ( _
   ByVal nImage As Long, ImagePixFmt As PixelFormat) As GpStatus
Private Declare Function GdipGetImageWidth Lib "gdiplus" ( _
   ByVal nImage As Long, Width As Long) As GpStatus
Private Declare Function GdipGetImageHeight Lib "gdiplus" ( _
   ByVal nImage As Long, Height As Long) As GpStatus

Private Function GdiErrorString(ByVal lError As GpStatus) As String
 Select Case lError
 Case GenericError:              GdiErrorString = "Generic error"
 Case InvalidParameter:          GdiErrorString = "Invalid parameter"
 Case OutOfMemory:               GdiErrorString = "Out of memory"
 Case ObjectBusy:                GdiErrorString = "Object busy"
 Case InsufficientBuffer:        GdiErrorString = "Insufficient buffer"
 Case NotImplemented:            GdiErrorString = "Not implemented"
 Case Win32Error:                GdiErrorString = "Win32 error"
 Case WrongState:                GdiErrorString = "Wrong state"
 Case Aborted:                   GdiErrorString = "Aborted"
 Case FileNotFound:              GdiErrorString = "File not found"
 Case ValueOverflow:             GdiErrorString = "Value overflow"
 Case AccessDenied:              GdiErrorString = "Access denied"
 Case UnknownImageFormat:        GdiErrorString = "Unknown image format"
 Case FontFamilyNotFound:        GdiErrorString = "Font family not found"
 Case FontStyleNotFound:         GdiErrorString = "Font style not found"
 Case NotTrueTypeFont:           GdiErrorString = "Not TrueType font"
 Case UnsupportedGdiplusVersion: GdiErrorString = "Unsupported GDI+ version"
 Case GdiplusNotInitialized:     GdiErrorString = "GDI+ not initialized"
 Case PropertyNotFound:          GdiErrorString = "Property not found"
 Case PropertyNotSupported:      GdiErrorString = "Property not supported"
 Case Else:                      GdiErrorString = "Unknown GDI+ error"
 End Select
End Function

Private Function GdipExec(ByVal lStatus As GpStatus) As GpStatus
 If lStatus <> OK Then MsgBox GdiErrorString(lStatus), vbExclamation, _
                              "GDI+ Error"
 GdipExec = lStatus
End Function


Public Function LoadARGBBmpAsEmfPicture( _
   ByVal FileName As String, _
   Optional ByVal bAlpha As Byte = 255, _
   Optional ByVal EMFFileName As String = vbNullString) As IPictureDisp
 Dim GdipToken As Long
 Dim si As GdiplusStartupInput
 Dim nBitmap As Long
 Dim hBitmap As Long
 Dim pfPixFmt As PixelFormat
 Dim cxWidth As Long, cyHeight As Long
 Dim hicRef As Long
 Dim iWidthMM As Long
 Dim iHeightMM As Long
 Dim iWidthPels As Long
 Dim iHeightPels As Long
 Dim iDPIX As Long
 Dim iDPIY As Long
 Dim rc As RECT
 Dim hdcMeta As Long
 Dim iWEX As Long, iWEY As Long
 Dim iVEX As Long, iVEY As Long
 Dim iGCD As Long
 Dim hdcMem As Long
 Dim hbmpOld As Long
 Dim hEMF As Long
 Dim bfBlend As BLENDFUNCTION
 Dim bfvBlend As BLENDFUNCTIONBYVAL

 si.GdiplusVersion = Ver1
 GdipExec GdiplusStartup(GdipToken, si, ByVal 0&)
 If GdipToken = 0 Then Exit Function
 GdipExec GdipCreateBitmapFromFile(StrPtr(FileName), nBitmap)
 If nBitmap Then
    GdipExec GdipGetImagePixelFormat(nBitmap, pfPixFmt)
    If pfPixFmt = PixelFormat32bppARGB Then
       GdipExec GdipGetImageWidth(nBitmap, cxWidth)
       GdipExec GdipGetImageHeight(nBitmap, cyHeight)
       GdipExec GdipCreateHBITMAPFromBitmap(nBitmap, hBitmap, &H0)
    Else
       MsgBox "Wrong image format!", vbExclamation
    End If
    GdipExec GdipDisposeImage(nBitmap): nBitmap = 0
 End If
 GdipExec GdiplusShutdown(GdipToken): GdipToken = 0
 If hBitmap = 0 Then Exit Function
 
 hicRef = CreateIC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
 iWidthMM = GetDeviceCaps(hicRef, HORZSIZE)
 iHeightMM = GetDeviceCaps(hicRef, VERTSIZE)
 iWidthPels = GetDeviceCaps(hicRef, HORZRES)
 iHeightPels = GetDeviceCaps(hicRef, VERTRES)
 iDPIX = GetDeviceCaps(hicRef, LOGPIXELSX)
 iDPIY = GetDeviceCaps(hicRef, LOGPIXELSY)
 
 'Размеры в сотых долях миллиметра
 rc.Right = Int(cxWidth * 2540 / iDPIX + 0.5)
 rc.Bottom = Int(cyHeight * 2540 / iDPIY + 0.5)
 
 'Создаём "усовершенствованный" метафайл в памяти и на диске, если дано имя
 hdcMeta = CreateEnhMetaFile(hicRef, EMFFileName, rc, vbNullString)
 
 iWEX = cxWidth * iWidthMM * iDPIX * 10
 iWEY = cyHeight * iHeightMM * iDPIY * 10
 iVEX = cxWidth * iWidthPels * 254
 iVEY = cyHeight * iHeightPels * 254
 iGCD = GCD(GCD(GCD(iWEX, iWEY), iVEX), iVEY)
 SetMapMode hdcMeta, MM_ANISOTROPIC
 SetWindowExtEx hdcMeta, iWEX \ iGCD, iWEY \ iGCD, ByVal 0&
 SetViewportExtEx hdcMeta, iVEX \ iGCD, iVEY \ iGCD, ByVal 0&
 
 hdcMem = CreateCompatibleDC(hicRef)
 DeleteDC hicRef: hicRef = 0
 hbmpOld = SelectObject(hdcMem, hBitmap)

 bfBlend.BlendOp = AC_SRC_OVER
 bfBlend.BlendFlags = 0
 bfBlend.SourceConstantAlpha = bAlpha
 bfBlend.AlphaFormat = AC_SRC_ALPHA
 LSet bfvBlend = bfBlend
 AlphaBlend hdcMeta, 0, 0, cxWidth, cyHeight, _
            hdcMem, 0, 0, cxWidth, cyHeight, bfvBlend.Value

 SelectObject hdcMem, hbmpOld: hbmpOld = 0
 DeleteDC hdcMem: hdcMem = 0
 DeleteObject hBitmap: hBitmap = 0
    
 hEMF = CloseEnhMetaFile(hdcMeta): hdcMeta = 0
 Set LoadARGBBmpAsEmfPicture = CreateIPictureDispFromHENHMETAFILE(hEMF)
End Function


Public Function CreateIPictureDispFromHENHMETAFILE( _
   ByVal hEMF As Long, _
   Optional ByVal bPictureOwnsHandle As Boolean = True) As IPictureDisp
 Dim IID_IPictureDisp As GUID
 Dim PictDesc As PICTDESCEMF
 With PictDesc
    .cbSizeOfStruct = Len(PictDesc)
    .PictType = PICTYPE_ENHMETAFILE
    .hEMF = hEMF
 End With
 CLSIDFromString StrPtr(IIDSTR_IPictureDisp), IID_IPictureDisp
 OleCreatePictureIndirect PictDesc, IID_IPictureDisp, -bPictureOwnsHandle, _
                          CreateIPictureDispFromHENHMETAFILE
End Function


Public Function GCD(ByVal a As Long, ByVal b As Long) As Long
 Do While (a <> 0) And (b <> 0)
    If a >= b Then a = a Mod b Else b = b Mod a
 Loop
 GCD = a + b
End Function



Подскажите, как сделать чтобы у картинки не было стрейча? Чтобы она не растягивалась.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #38806777
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Eolt,

краткость не всегда сестра таланта. Вас ответ "cтретча нет, картинка не растягивается" устроит?

Код специально писался для того, чтобы "не было стретча" на формах VB, Access-а и отчётах Access-а.
Если Вы утверждаете иное, или для других условий, будьте добры обосновать утверждение.
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #38807107
Eolt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
БенедиктEolt,

краткость не всегда сестра таланта. Вас ответ "cтретча нет, картинка не растягивается" устроит?

Код специально писался для того, чтобы "не было стретча" на формах VB, Access-а и отчётах Access-а.
Если Вы утверждаете иное, или для других условий, будьте добры обосновать утверждение.

Тем не менее стрейч есть.

Код: vbnet
1.
2.
3.
4.
5.
6.
Option Explicit

Private Sub Command1_Click()
 Set Form2.Picture = LoadARGBBmpAsEmfPicture(App.Path & "\lgc207.png")
 
End Sub
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #38807605
Фотография Бенедикт
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Eolt,
Код: vbnet
1.
2.
 Form2.AutoRedraw = True
 Form2.PaintPicture LoadARGBBmpAsEmfPicture(App.Path & "\lgc207.png"), X, Y

или положить на форму Image и сделать
Код: vbnet
1.
2.
 'Form2.Image1.Stretch = False
 Set Form2.Image1.Picture = LoadARGBBmpAsEmfPicture(App.Path & "\lgc207.png")

или положить на форму Picture и сделать
Код: vbnet
1.
2.
 Form2.Picture1.AutoSize = True
 Set Form2.Picture1.Picture = LoadARGBBmpAsEmfPicture(App.Path & "\lgc207.png")
...
Рейтинг: 0 / 0
.png и Visual Basic 6
    #38807933
Eolt
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Бенедикт,

спасибо!
...
Рейтинг: 0 / 0
22 сообщений из 22, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / .png и Visual Basic 6
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]