
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.206.48.243] |
![]() |
|
Сообщ.
#1
,
|
|
|
По ряду причин необходимо сделать простенькое приложение в AutoPlay Media Studio - конвертер изображений. Согласно представленному здесь примеру набросал код:
![]() ![]() gdiplusToken = 0; -- exit application function AppExit() -- free image if (image and MemoryEx.DWORD(image) ~= 0) then GDIE_STATE = GDI.GdipDisposeImage(image); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("GDI error", "GdipDisposeImage: " .. GDI_ERROR[GDIE_STATE]); end end -- shutdown GDI+ if (gdiplusToken ~= 0) then GDIE_STATE = GDI.GdiplusShutdown(gdiplusToken); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("GDI error", "GdiplusShutdown: " .. GDI_ERROR[GDIE_STATE]); end end -- free some memory if (zero) then MemoryEx.Free(zero); end if (pfilePNG) then MemoryEx.Free(pfilePNG); end if (pCLSID) then MemoryEx.Free(pCLSID); end if (pstrCLSID) then MemoryEx.Free(pstrCLSID); end if (image) then MemoryEx.Free(image); end if (pfileBMP) then MemoryEx.Free(pfileBMP); end if (pgdiplusStartupInput) then MemoryEx.Free(pgdiplusStartupInput); end if (pgdiplusToken) then MemoryEx.Free(pgdiplusToken); end Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE); end -- loading libraries OLE = Library.Load("OLE32.dll"); GDI = Library.Load("GDIPLUS.dll"); -- GDI+ error codes GDI_OK = 0; GDI_STATE = 0; GDI_ERROR = {"GenericError", "InvalidParameter", "OutOfMemory", "ObjectBusy", "InsufficientBuffer", "NotImplemented", "Win32Error", "WrongState", "Aborted", "FileNotFound", "ValueOverflow", "AccessDenied", "UnknownImageFormat", "FontFamilyNotFound", "FontStyleNotFound", "NotTrueTypeFont", "UnsupportedGdiplusVersion", "GdiplusNotInitialized", "PropertyNotFound", "PropertyNotSupported", "ProfileNotFound"}; -- define file paths local fileBMP = _SourceFolder .. "\\AutoPlay\\Images\\i.bmp" local filePNG = _SourceFolder .. "\\AutoPlay\\Images\\o.png"; -- pointer to GDI+ Token pgdiplusToken = MemoryEx.Allocate(4); -- define structure gdiplusStartupInput local gdiplusStartupInput = MemoryEx.DefineStruct{UDWORD ("GdiplusVersion"); UDWORD ("DebugEventCallback"); BYTE ("SuppressBackgroundThread"); BYTE ("SuppressExternalCodecs");}; -- create structure gdiplusStartupInput local hgdiplusStartupInput = gdiplusStartupInput:New(); -- fill structure gdiplusStartupInput hgdiplusStartupInput.GdiplusVersion = 1; hgdiplusStartupInput.DebugEventCallback = 0; hgdiplusStartupInput.SuppressBackgroundThread = false; hgdiplusStartupInput.SuppressExternalCodecs = false; -- pointer to structure gdiplusStartupInput pgdiplusStartupInput = hgdiplusStartupInput:GetPointer(); -- init GDI+ GDIE_STATE = GDI.GdiplusStartup(pgdiplusToken, pgdiplusStartupInput, 0); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("GDI error", "GdiplusStartup: " .. GDI_ERROR[GDIE_STATE]); Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE); end gdiplusToken = MemoryEx.DWORD(pgdiplusToken); if (gdiplusToken == 0) then Dialog.Message("GDI error", "gdiplusToken: 0"); Window.Close(Application.GetWndHandle(), CLOSEWND_TERMINATE); end -- path to source image file (Unicode, NULL terminated) pfileBMP = MemoryEx.Allocate(String.Length(fileBMP) * 2 + 1); MemoryEx.String(pfileBMP, -1, MEMEX_UNICODE, fileBMP); image = MemoryEx.Allocate(4); -- loading source image GDIE_STATE = GDI.GdipLoadImageFromFile(pfileBMP, image); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("GDI error", "GdipLoadImageFromFile: " .. GDI_ERROR[GDIE_STATE]); AppExit(); end -- get PNG encoder ID local strCLSID = "{557CF406-1A04-11D3-9A73-0000F81EF32E}"; pstrCLSID = MemoryEx.Allocate(String.Length(strCLSID) * 2 + 1); MemoryEx.String(pstrCLSID, -1, MEMEX_UNICODE, strCLSID); pCLSID = MemoryEx.Allocate(16); GDIE_STATE = OLE.CLSIDFromString(pstrCLSID, pCLSID); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("OLE32 error", "CLSIDFromString: " .. GDIE_STATE); AppExit(); end -- pCLSID is a pointer to 16-bytes binary encoder ID, must be 0x06F47C55041AD3119A730000F81EF32E (checked) -- path to output image file (Unicode, NULL terminated) pfilePNG = MemoryEx.Allocate(String.Length(filePNG) * 2 + 1); MemoryEx.String(pfilePNG, -1, MEMEX_UNICODE, filePNG); zero = MemoryEx.Allocate(4); -- pointer to constant [DWORD] = 0, info here http://www.vbforums.com/showthread.php?663593.html -- save image as PNG-file GDIE_STATE = GDI.GdipSaveImageToFile(image, pfilePNG, pCLSID, zero); if (GDIE_STATE ~= GDI_OK) then Dialog.Message("GDI error", "GdipSaveImageToFile: " .. GDI_ERROR[GDIE_STATE]); AppExit(); end Dialog.Message("GDI", "PNG file saved!"); Но функции GdipSaveImageToFile и в дальнейшем GdipDisposeImage возвращают код ошибки ObjectBusy. Подскажите, пожалуйста, что может быть не так? |
Сообщ.
#2
,
|
|
|
M Представленный код - не на языках C/C++ (вероятно, Lua?). Поэтому переезжаем? |
Сообщ.
#3
,
|
|
|
JoeUser вопрос всё таки по работе Win API (GDI+)...? Сам код на основе Lua конечно.
|
Сообщ.
#4
,
|
|
|
Разобрался вроде с загрузкой и сохранением. Если кто знает как средствами GDI+ задать определенному цвету значение альфы? (чтобы сделать его полупрозрачным)
|
Сообщ.
#5
,
|
|
|
![]() ![]() Gdiplus::Pen pen(Gdiplus::Color(96, 0, 0, 255)); // alpha, red, green, blue |