Wie kann ich eine Bild-Datei zentriert in ein ImageGadget plazieren ?
Es darf kein ResizeGadget verwendet werden um event. das imageGadget zu justieren.
Das definierte ImageGadget hat 200*200.
Wen ich ein Jpg-Datei mit der Größe 100*100 lade wird es in die linke obere Ecke gesetzt.
Für eine Hilfe bin ich Euch sehr dankbar.
Grüße
Lite
Code: Alles auswählen
CompilerIf Defined(GdiplusStartupInput, #PB_Structure) = 0
Structure GdiplusStartupInput
GdiPlusVersion.l
*DebugEventCallback.Debug_Event
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
CompilerEndIf
CallFunction(lib, "GdiplusStartup", @*token, @input, #Null)
Procedure _SetImage(sid,File$)
If FileSize(File$) < 1 : ProcedureReturn: EndIf
ReadFile(0, File$)
*mempic = AllocateMemory(Lof(0))
ReadData(0, *mempic, Lof(0))
; gdi plus
Define Streammem
Protected lib
lib = OpenLibrary(#PB_Any, "gdiplus.dll")
If lib
input.GdiplusStartupInput
input\GdiPlusVersion = 1
CallFunction(lib, "GdiplusStartup", @*token, @input, #Null)
If *token
*pmem = GlobalAlloc_(#GHND, MemorySize(*mempic))
*hmem = GlobalLock_(*pmem)
CopyMemory(*mempic, *hmem, MemorySize(*mempic))
FreeMemory(*mempic)
If CreateStreamOnHGlobal_(*hmem, 0, @Streammem) = #S_OK
CallFunction(lib, "GdipCreateBitmapFromStream", Streammem , @*image)
CallFunction(lib, "GdipGetImageWidth", *image, @width)
CallFunction(lib, "GdipGetImageHeight", *image, @height)
; Debug "Breite: "+width
; Debug "höhe: "+height
CallFunction(lib, "GdipCreateHBITMAPFromBitmap", *image, @imageid, -1)
CallFunction(lib, "GdipDisposeImage", *image)
CallFunction(lib, "GdiplusShutdown", *token)
CloseLibrary(lib)
EndIf
If width>0 Or height>0
img = CreateImage(#PB_Any, width, height, 32,#PB_Image_Transparent )
StartDrawing(ImageOutput(img))
If imageid <>0: DrawAlphaImage(imageid,0,0): EndIf
StopDrawing()
SetGadgetState(sid,ImageID(img))
FreeImage(img)
Else
SetGadgetState(sid,0)
ProcedureReturn 0
EndIf
EndIf
EndIf
ProcedureReturn 1
EndProcedure
If OpenWindow(0, 0, 0, 545, 405, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
FrameGadget(0, 9, 9, 202, 202, "", #PB_Frame_Flat)
ImageGadget(1, 10, 10, 200, 200, 0) ; Imagegadget Standard
inpath$ = OpenFileRequester("jpg:", "", "jpg|*.jpg;", 0)
_SetImage(1,inpath$ )
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf