Code: Select all
UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
Global hEmf
SourceFile$ = OpenFileRequester("SELECT IMAGE","","All supported formats|*.bmp;*.jpg; *.jpeg;*.png;*.tif;*.tiff;*.tga|TGA image (*.tga)|*.tga|TIF image (*.tif)|*.tif|TIFF image (*.tiff)|*.tiff| PNG image (*.png)|*.png|BMP image (*.bmp)|*.bmp|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg",0)
If SourceFile$
LoadImage(1, SourceFile$)
Else
End
EndIf
w = ImageWidth(1)
h = ImageHeight(1)
des_img$ = GetTemporaryDirectory()+GetFilePart(SourceFile$, #PB_FileSystem_NoExtension) + ".emf"
emf_hDC = CreateEnhMetaFile_(0, @des_img$, 0, 0)
If emf_hDC
img_hDC = CreateCompatibleDC_(emf_hDC)
oldImage = SelectObject_(img_hDC, ImageID(1))
BitBlt_(emf_hDC, 0, 0, w,h, img_hDC, 0, 0, #SRCCOPY)
SelectObject_(img_hDC, oldImage)
DeleteDC_(img_hDC)
hEMF = CloseEnhMetaFile_(emf_hDC)
DeleteEnhMetaFile_(hEMF)
EndIf
Procedure WndProc(hwnd, uMsg, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_SIZE,#WM_SIZING,#WM_MOVE,#WM_MOVING
CreateImage(0,WindowWidth(0)-20, WindowHeight(0)-20)
hDC = StartDrawing(ImageOutput(0))
SetRect_(r.RECT, 0, 0, WindowWidth(0) - 20, WindowHeight(0) - 20)
PlayEnhMetaFile_(hDC, hEmf,r)
StopDrawing()
ResizeGadget(1,10,10,WindowWidth(0) - 20, WindowHeight(0)-20)
SetGadgetState(1,ImageID(0))
EndSelect
ProcedureReturn Result
EndProcedure
hWnd=OpenWindow(0,0,0,w+20,h+20,"Convert to EMF",#PB_Window_SystemMenu| #PB_Window_SizeGadget| #PB_Window_ScreenCentered)
SetWindowCallback(@WndProc())
CreateImage(0, w,h)
hEMF=GetEnhMetaFile_(@des_img$)
hDC = StartDrawing(ImageOutput(0))
SetRect_(r.RECT, 0, 0, w,h)
PlayEnhMetaFile_(hDC, hEmf,r)
StopDrawing()
ImageGadget(1, 10,10,w,h,ImageID(0))
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteEnhMetaFile_(hEMF)
ReleaseDC_(hWnd, hDC)