avec sauvegarde en BMP ou JPG, PNG et Clipboard.
voila! et aussi ajoute la saisie de la taille fenêtre.
de soucis, a moins d'un bureau multisession autre que zéro pour DesktopWidth(0) , DesktopHeight(0), voila!
Code : Tout sélectionner
; English forum:
; Author: Unknown (updated for PB 4.00 by Deeem2031)
; Date: 10. March 2003
; OS: Windows
; Demo: No
;###################################################################
; extrait de code achive pour visualiser des images, au quel #
; j'ai ajouter le code du zoom wheel move deplacement avec #
; le clic gauche et changement bouton en menu, Space=rotation, #
; Fleche=distorsion et miroir, page=Zoomfin, Sauvegarde vers #
; Clipboard et Sauve avec n° les images C:\Temp.BMP ou JPG , PNG #
; dialoque de saisie pour la taille de la fenetre afin de preparer #
; le format des images carrée pour la création d'icones textures #
; en 32x32 ou 48x48 format PNG pour conserver les couleurs #
; dialogue avec choix de sauver la taille X Y en BMP JPG PNG #
; ## Kernadec 09.2008 ## #
;###################################################################
#E_POINTER2 = $80000005
#E_NOINTERFACE2 = $80000004
#E_OUTOFMEMORY2 = $80000002
#IPicture_Release = 8
#IPicture_Get_Width = 24
#IPicture_Get_Height = 28
#IPicture_Render = 32
imgw.l=600
imgh.l=470
wl.l=600
wh.l=470
nbbmp$=""
nbjpg$=""
nbpng$=""
iconex.l=32:iconeY.l=32
Global hWindow, pstm.IStream, gpPicture.IPicture, hmwidth, hmheight, Width, Height,FileSize,Bitmap.l
Procedure Image_Rotate(image.l)
; Procedure Image Rotating Code by Paul Leischow Compiler: PB 4.00
Height=ImageHeight(image)
Width=ImageWidth(image)
If Height>Width
temp=CreateImage(#PB_Any,Height,Height)
Else
temp=CreateImage(#PB_Any,Width,Width)
EndIf
Dim rect.POINT(2)
rect(0)\x=Height
rect(0)\y=0
rect(1)\x=Height
rect(1)\y=Width
rect(2)\x=0
rect(2)\y=0
DC=StartDrawing(ImageOutput(temp))
DrawImage(ImageID(image),0,0)
PlgBlt_(DC,@rect(),DC,0,0,Width,Height,0,0,0)
StopDrawing()
GrabImage(temp,image,0,0,Height,Width)
FreeImage(temp)
EndProcedure
Procedure CaptureScreen(left.l, top.l, Width.l, Height.l)
; Author: wayne1 Date: 30. January 2002
dm.DEVMODE
BMPHandle.l
srcDC = CreateDC_("DISPLAY", "", "", dm)
trgDC = CreateCompatibleDC_(srcDC)
BMPHandle = CreateCompatibleBitmap_(srcDC, Width-10, Height-56) ;ajustement pour windows menu et barre
SelectObject_( trgDC, BMPHandle)
; bitbloc avec ajustement pour windows menu et barre
BitBlt_( trgDC, 0,0, Width+10, Height+4, srcDC, left+6, top+52, #SRCCOPY)
DeleteDC_( trgDC)
ReleaseDC_( BMPHandle, srcDC)
OpenClipboard_(#Null)
EmptyClipboard_()
SetClipboardData_(2,BMPHandle)
ciHwnd = GetClipboardData_(#CF_BITMAP)
If ciHwnd
GetObject_(ciHwnd, SizeOf(BITMAP), bm.BITMAP)
CreateImage(2, Width-10, Height-56)
StartDrawing(ImageOutput(2))
DrawImage(ciHwnd, 0, 0)
StopDrawing()
EndIf
EndProcedure
Procedure.w MouseWheelDelta()
xx.w = ((EventwParam()>>16)&$FFFF)
ProcedureReturn -(xx / 100)
EndProcedure
Procedure OleOpen(file$)
hBitmap = 0
If ReadFile(0, file$)
FileSize = FileSize(file$)
hGlobal = GlobalAlloc_(#GMEM_MOVEABLE, FileSize)
pvData = GlobalLock_(hGlobal)
ReadData(0,pvData, FileSize)
CloseFile(0)
GlobalUnlock_(hGlobal)
CreateStreamOnHGlobal_(hGlobal, #True, @pstm)
ErrorNumber = 0
Select OleLoadPicture_(pstm, FileSize, #False, ?IID_IPicture, @gpPicture)
Case #E_POINTER2
ErrorNumber = 222
Case #E_NOINTERFACE2
ErrorNumber = 223
Case #E_OUTOFMEMORY2
ErrorNumber = 224
EndSelect
pstm\Release() ;CallCOM(#IPicture_Release, pstm)
GlobalFree_(hGlobal)
If ErrorNumber=0
gpPicture\Get_Width(@hmwidth) ;CallCOM(#IPicture_Get_Width, gpPicture, @hmwidth)
gpPicture\Get_Height(@hmheight) ;CallCOM(#IPicture_Get_Height, gpPicture, @hmheight)
hdc = GetDC_(hWindow)
xScreenPixels = GetDeviceCaps_(hdc, #LOGPIXELSX)
yScreenPixels = GetDeviceCaps_(hdc, #LOGPIXELSY)
Width = Abs((hmwidth*xScreenPixels)/2540)
Height = Abs((hmheight*yScreenPixels)/2540)
rc.RECT
rc\left = 0
rc\top = 0
rc\right = Width
rc\bottom = Height
mDC = CreateCompatibleDC_(hdc)
hBitmap = CreateCompatibleBitmap_(hdc, Width, Height)
OldBitmap = SelectObject_(mDC, hBitmap)
gpPicture\Render(mDC, 0, 0, Width, Height, 0, hmheight, hmwidth, -hmheight, rc) ;CallCOM(#IPicture_Render, gpPicture, mDC, 0, 0, width, height, 0, hmheight, hmwidth, -hmheight, rc)
SelectObject_(mDC, OldBitmap)
DeleteDC_(mDC)
ReleaseDC_(hWindow, hdc)
gpPicture\Release() ;CallCOM(#IPicture_Release, gpPicture)
EndIf
EndIf
ProcedureReturn hBitmap
EndProcedure
If OleInitialize_(0)=#S_OK
hWindow = OpenWindow(0, 0, 0,wl,wh, "",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget |#PB_Window_Invisible| #PB_Window_ScreenCentered|#WS_OVERLAPPEDWINDOW )
If hWindow
filename$ = OpenFileRequester("Open image", "", "JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|Icon file (*.ico)|*.ico|Cursor file (*.cur)|*.cur|BMP image (*.bmp)|*.bmp|GIF image (*.gif)|*.gif|Windows Metafile (*.wmf)|*.wmf|Enhanced Metafile (*.emf)|*.emf", 0)
If filename$
ImageID = OleOpen(filename$)
If CreateGadgetList(hWindow) And ImageID
If CreateMenu(2,WindowID(0))
MenuTitle("Fichier ")
MenuItem(3,"Ouvrir")
OpenSubMenu(" Sauver") ; Crée un sous-menu
MenuItem(5,"C:\Temp.BMP")
MenuItem(6,"C:\Temp.JPG")
MenuItem(7,"C:\Temp.PNG")
CloseSubMenu()
MenuBar()
OpenSubMenu("Sauve 32-48")
MenuItem(8,"C:\32x32Temp.PNG")
MenuItem(9,"C:\48x48Temp.PNG")
CloseSubMenu()
OpenSubMenu("Sauve X/Y")
MenuItem(10,"C:\X-YTemp.BMP")
MenuItem(11,"C:\X-YTemp.JPG")
MenuItem(12,"C:\X-YTemp.PNG")
CloseSubMenu()
MenuBar()
OpenSubMenu(" Infos") ; Crée un sous-menu
MenuItem(13,"Espace=Rotation")
MenuItem(14,"Page=Zoom Fin")
MenuItem(15,"Flèches <^>=Déforme")
CloseSubMenu()
MenuItem(16,"WindowsXY")
MenuItem(17,"Mask Coul")
MenuItem(4,"Quitter")
EndIf
ExamineDesktops()
CreateImage(0,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
StartDrawing(ImageOutput(0))
DrawImage(ImageID, 0, 0 ,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
StopDrawing()
CreateImage(1,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
ImageGadget(1,0,0,imgw,imgh, ImageID(1) , #PB_Image_Border)
HideWindow(0,0)
PosX1=0
PosY1=0
bm=#False
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Menu
If EventMenu() = 3
filename$ = OpenFileRequester("Open image", "", "JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|Icon file (*.ico)|*.ico|Cursor file (*.cur)|*.cur|BMP image (*.bmp)|*.bmp|GIF image (*.gif)|*.gif|Windows Metafile (*.wmf)|*.wmf|Enhanced Metafile (*.emf)|*.emf", 0)
If filename$
ImageID = OleOpen(filename$)
If ImageID
ExamineDesktops()
FreeImage(0):FreeImage(1):FreeImage(2):imgw=WindowWidth(0):imgh=WindowHeight(0):xmx=0:ymy=0
CreateImage(0,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
StartDrawing(ImageOutput(0))
DrawImage(ImageID, 0, 0 ,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
StopDrawing()
CreateImage(1,imgw+DesktopWidth(0),imgh+DesktopHeight(0))
ImageGadget(1,0,0,imgw,imgh, ImageID(1) , #PB_Image_Border)
HideWindow(0,0)
EndIf
EndIf
EndIf
If EventMenu() = 4
event=16
EndIf
If EventMenu() = 5
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
nbbmp$=Str(Val(nbbmp$)+1)
SaveImage(2,"C:\temp"+nbbmp$+".bmp",#PB_ImagePlugin_BMP)
CloseClipboard_()
EndIf
If EventMenu() = 6
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
UseJPEGImageEncoder()
nbjpg$=Str(Val(nbjpg$)+1)
SaveImage(2,"C:\temp"+nbjpg$+".jpg",#PB_ImagePlugin_JPEG)
CloseClipboard_()
EndIf
If EventMenu() = 7
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
UsePNGImageEncoder()
nbpng$=Str(Val(nbpng$)+1)
SaveImage(2,"C:\temp"+nbpng$+".png",#PB_ImagePlugin_PNG)
CloseClipboard_()
EndIf
If EventMenu() = 8
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
ResizeImage(2, 32,32,#PB_Image_Smooth)
UsePNGImageEncoder()
nbpng$=Str(Val(nbpng$)+1)
SaveImage(2,"C:\32x32temp"+nbpng$+".png",#PB_ImagePlugin_PNG)
CloseClipboard_()
EndIf
If EventMenu() = 9
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
ResizeImage(2, 48,48,#PB_Image_Smooth)
UsePNGImageEncoder()
nbpng$=Str(Val(nbpng$)+1)
SaveImage(2,"C:\48x48temp"+nbpng$+".png",#PB_ImagePlugin_PNG)
CloseClipboard_()
EndIf
If EventMenu() = 10 Or EventMenu() = 11 Or EventMenu() = 12
choix=EventMenu()
If choix=10:ext$="BMP":EndIf
If choix=11:ext$="JPG":EndIf
If choix=12:ext$="PNG":EndIf
If OpenWindow(2,25,250,180,70,"Redim. et Sauve "+ext$,#PB_Window_SystemMenu)
CreateGadgetList(WindowID(2))
StringGadget(30,48,10,30,20,Str(iconex),#PB_String_Numeric)
TextGadget(31,10,14,50,20,"Taille X")
StringGadget(32,128,10,30,20,Str(iconeY),#PB_String_Numeric)
TextGadget(33,90,14,50,20,"Taille Y")
ButtonGadget(34,20,40,60,20,"Annuler")
ButtonGadget(35,100,40,60,20,"OK")
SendMessage_(GadgetID(30), #EM_LIMITTEXT, 4, 0)
SendMessage_(GadgetID(32), #EM_LIMITTEXT, 4, 0)
EndIf
Repeat
event3=WindowEvent()
Select event3
Case #PB_Event_CloseWindow
CloseWindow(2)
Break
EndSelect
If event3=#PB_Event_Gadget
Select EventMenu()
Case 34
CloseWindow(2)
Break
Case 35
HideWindow(2,1)
iconex=Val(GetGadgetText(30))
iconeY=Val(GetGadgetText(32))
WindowSize.RECT
GetWindowRect_(hWindow, @WindowSize)
CaptureScreen(WindowSize\left, WindowSize\top, WindowSize\right - WindowSize\left, WindowSize\bottom - WindowSize\top)
ImageGadget(0,0,0,WindowWidth(0),WindowHeight(0),Bitmap)
ResizeImage(2,iconex,iconeY,#PB_Image_Smooth)
If choix = 10
nbbmp$=Str(Val(nbbmp$)+1)
SaveImage(2,"C:\"+Str(iconex)+"x"+Str(iconeY)+"temp"+nbbmp$+".bmp",#PB_ImagePlugin_BMP)
EndIf
If choix = 11
UseJPEGImageEncoder()
nbjpg$=Str(Val(nbjpg$)+1)
SaveImage(2,"C:\"+Str(iconex)+"x"+Str(iconeY)+"temp"+nbjpg$+".jpg",#PB_ImagePlugin_JPEG)
EndIf
If choix = 12
UsePNGImageEncoder()
nbpng$=Str(Val(nbpng$)+1)
SaveImage(2,"C:\"+Str(iconex)+"x"+Str(iconeY)+"temp"+nbpng$+".png",#PB_ImagePlugin_PNG)
EndIf
CloseClipboard_()
CloseWindow(2)
Break
EndSelect
EndIf
ForEver
EndIf
If EventMenu() = 16
If OpenWindow(1,25,150,180,70,"Taille Fenêtre",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(1))
StringGadget(20,48,10,30,20,Str(WindowWidth(0)-2),#PB_String_Numeric)
TextGadget(21,10,14,50,20,"Taille X")
StringGadget(22,128,10,30,20,Str(WindowHeight(0)-22),#PB_String_Numeric)
TextGadget(23,90,14,50,20,"Taille Y")
ButtonGadget(24,20,40,60,20,"Annuler")
ButtonGadget(25,100,40,60,20,"OK")
SendMessage_(GadgetID(20), #EM_LIMITTEXT, 4, 0)
SendMessage_(GadgetID(22), #EM_LIMITTEXT, 4, 0)
EndIf
Repeat
event2=WindowEvent()
Select event2
Case #PB_Event_CloseWindow
CloseWindow(1)
Break
EndSelect
If event2=#PB_Event_Gadget
Select EventMenu()
Case 24
CloseWindow(1)
Break
Case 25
HideWindow(1,1)
ResizeWindow(0,WindowX(0),WindowY(0),Val(GetGadgetText(20))+2, Val(GetGadgetText(22))+22)
SetGadgetText(20,Str(WindowWidth(0)+2))
SetGadgetText(22,Str(WindowHeight(0)+22))
CloseWindow(1)
Break
EndSelect
EndIf
ForEver
EndIf
If EventMenu() = 17
Color.l = ColorRequester()
If Color > -1
coulfr1=Red(Color)
coulfr2=Green(Color)
coulfr3=Blue(Color)
FreeImage(0)
CreateImage(0,imgw+xmx,imgh+ymy)
StartDrawing(ImageOutput(0))
Box(0,0,WindowWidth(0)+wl,WindowHeight(0)+wh,RGB(coulfr1,coulfr2,coulfr3))
DrawImage(ImageID(0),PosX1-(xmx/2),PosY1-(ymy/2),imgw+xmx,imgh+ymy)
StopDrawing()
EndIf
EndIf
EndIf
If event = #WM_MOUSEWHEEL
xmx=xmx+(MouseWheelDelta() *20)
ymy=ymy+(MouseWheelDelta() *20)
EndIf
If event = #WM_RBUTTONUP
bm=#False
EndIf
If event = #WM_RBUTTONDOWN
bm=#True
PosX = WindowMouseX(0)-PosX1
PosY = WindowMouseY(0)-PosY1
EndIf
If event = #WM_MOUSEMOVE
If bm=#True
PosX1 = WindowMouseX(0)-PosX
PosY1 = WindowMouseY(0)-PosY
EndIf
EndIf
StartDrawing( ImageOutput(1) );
Box(0,0,WindowWidth(0)+wl,WindowHeight(0)+wh,RGB(coulfr1,coulfr2,coulfr3))
DrawImage(ImageID(0),PosX1-(xmx/2),PosY1-(ymy/2),(imgw-2)+xmx,(imgh-22)+ymy)
Tailleix$=(Str((imgw+xmx)-2))
Tailleiy$=(Str((imgh+ymy)-22))
Taillewx$=(Str(WindowWidth(0)-2))
Taillewy$=(Str(WindowHeight(0)-22))
SetWindowTitle(0,"WX: "+Taillewx$+" WY: "+Taillewy$+" IMX: "+Tailleix$+" IMY: "+Tailleiy$+" Load Picture Exemple Zoom Wheel Move")
StopDrawing()
SetGadgetState(1,ImageID(1))
If event = #WM_KEYDOWN ; Commande clavier
key = EventwParam()
EndIf
If key=39
Wheel+1
xmx=xmx+Wheel/10
key=20 ;pour eviter la repetition auto
EndIf
If key=37
Wheel+1
xmx=xmx-Wheel/10
key=20
EndIf
If key=38
Wheel+1
ymy=ymy+Wheel/10
key=20
EndIf
If key=40
Wheel+1
ymy=ymy-Wheel/10
key=20
EndIf
If key=33
Wheel+1
xmx=xmx+Wheel/20
ymy=ymy+Wheel/20
key=20
EndIf
If key=34
Wheel+1
xmx=xmx-Wheel/20
ymy=ymy-Wheel/20
key=20
EndIf
If key=32
Image_Rotate(0)
key=20
EndIf
Until event = #PB_Event_CloseWindow Or key = 27
EndIf
EndIf
EndIf
OleUninitialize_()
EndIf
End
!section '.data' Data readable writeable
IID_IPicture:
!DD $07BF80980
!DW $0BF32, $0101A
!DB $08B, $0BB, 0, $0AA, 0, $030, $0C, $0AB