J'ai glané ici et là des bouts de code pour 2crire celui-ci qui envoie sur l'imprimante une copie d'écran grand format !
Code : Tout sélectionner
ProcedureDLL.l RotateImageEx2(ImageID, Angle.f)
Protected bmi.BITMAPINFO, bmi2.BITMAPINFO, Hdc.l, NewImageID, Mem, n, nn, bm.BITMAP
;radian conversion
Debug "Angle : "+Str(Angle)
Angle*#PI/180
Protected Cos.f = Cos(Angle)
Protected Sin.f = Sin(Angle)
Protected CouleurFond = 0
GetObject_(ImageID, SizeOf(BITMAP), @bm.BITMAP)
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = bm\bmWidth
bmi\bmiHeader\biHeight = bm\bmHeight
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
bmi2\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi2\bmiHeader\biWidth = bm\bmWidth * Abs(Cos) + bm\bmHeight * Abs(Sin)
bmi2\bmiHeader\biHeight = bm\bmHeight * Abs(Cos) + bm\bmWidth * Abs(Sin)
bmi2\bmiHeader\biPlanes = 1
bmi2\bmiHeader\biBitCount = 32
bmi2\bmiHeader\biCompression = #BI_RGB
Mem = AllocateMemory(bm\bmWidth * bm\bmHeight * 4)
If Mem
Protected Mem2 = AllocateMemory(bmi2\bmiHeader\biWidth * bmi2\bmiHeader\biHeight * 4)
If Mem2
;retrieves the bits of the specified bitmap and copies them into a buffer
Hdc = CreateCompatibleDC_(GetDC_(ImageID))
If Hdc
GetDIBits_(Hdc, ImageID, 0, bm\bmHeight, Mem, @bmi, #DIB_RGB_COLORS)
ReleaseDC_(0, Hdc)
EndIf
Protected CX1 = bm\bmWidth - 1
Protected CY1 = bm\bmHeight - 1
Protected CX2 = bmi2\bmiHeader\biWidth - 1
Protected CY2 = bmi2\bmiHeader\biHeight - 1
Protected Mem01 = Mem + bm\bmWidth * 4
Protected Mem10 = Mem + 4
Protected Mem11 = Mem01 + 4
Protected Mem2Temp = Mem2
Protected deb=-CX2/2
Protected fin=deb+CX2;= Round(CX2/2,1) but <> (CX2*2-CX2)/2
For nn = 0 To CY2
Protected x1b.l
Protected y1b.l = (nn * 2) - CY2
Protected Temp1.f = (CX1 - (y1b * Sin))/2
Protected Temp2.f = (CY1 + (y1b * Cos))/2
Protected x1.f = Temp1 + (deb * Cos)
Protected y1.f = Temp2 + (deb * Sin)
For x1b = deb To fin
;could be faster with arrays
Protected x2.l = x1
Protected y2.l = y1
If x1 < x2
!DEC dword[p.v_x2]
EndIf
If y1 < y2
!DEC dword[p.v_y2]
EndIf
Protected x2b.l = x2 + 1
Protected y2b.l = y2 + 1
;test boundaries
If x2b >= 0 And x2 <= CX1 And y2b >= 0 And y2 <= CY1
Protected fx.f = x1 - x2
Protected fy.f = y1 - y2
Protected f00.f = 1 - fx
Protected f10.f = 1 - fy
Protected f01.f = f00 * fy
f00 * f10
f10 * fx
Protected f11.f = fx * fy
Protected MemTemp = (x2 + y2 * bm\bmWidth) * 4
Protected c00.l, c01.l, c11.l, c10.l
If x2 >= 0 And x2 <= CX1
If y2 >= 0 And y2 <= CY1
!MOV eax,dword[p.v_Mem]
!ADD eax,dword[p.v_MemTemp]
!MOV eax,dword[eax]
!MOV dword[p.v_c00],eax
;c00 = PeekL(Mem + MemTemp)
Else
c00 = 0
EndIf
If y2b >= 0 And y2b <= CY1
!MOV eax,dword[p.v_Mem01]
!ADD eax,dword[p.v_MemTemp]
!MOV eax,dword[eax]
!MOV dword[p.v_c01],eax
;c01 = PeekL(Mem01 + MemTemp)
Else
c01 = 0
EndIf
Else
c00 = 0
c01 = 0
EndIf
If x2b >= 0 And x2b <= CX1
If y2 >= 0 And y2 <= CY1
!MOV eax,dword[p.v_Mem10]
!ADD eax,dword[p.v_MemTemp]
!MOV eax,dword[eax]
!MOV dword[p.v_c10],eax
;c10 = PeekL(Mem10 + MemTemp)
Else
c10 = 0
EndIf
If y2b >= 0 And y2b <= CY1
!MOV eax,dword[p.v_Mem11]
!ADD eax,dword[p.v_MemTemp]
!MOV eax,dword[eax]
!MOV dword[p.v_c11],eax
;c11 = PeekL(Mem11 + MemTemp)
Else
c11 = 0
EndIf
Else
c10 = 0
c11 = 0
EndIf
Protected r1.l,r2.l,r3.l,r4.l,g1.l,g2.l,g3.l,g4.l,b1.l,b2.l,b3.l,b4.l
!MOV eax,dword[p.v_c00]
!MOV ebx,eax
!MOV ecx,eax
!AND eax,$FF
!MOV dword[p.v_r1],eax
!AND ebx,$FF00
!MOV dword[p.v_g1],ebx
!AND ecx,$FF0000
!MOV dword[p.v_b1],ecx
!MOV eax,dword[p.v_c10]
!MOV ebx,eax
!MOV ecx,eax
!AND eax,$FF
!MOV dword[p.v_r2],eax
!AND ebx,$FF00
!MOV dword[p.v_g2],ebx
!AND ecx,$FF0000
!MOV dword[p.v_b2],ecx
!MOV eax,dword[p.v_c01]
!MOV ebx,eax
!MOV ecx,eax
!AND eax,$FF
!MOV dword[p.v_r3],eax
!AND ebx,$FF00
!MOV dword[p.v_g3],ebx
!AND ecx,$FF0000
!MOV dword[p.v_b3],ecx
!MOV eax,dword[p.v_c11]
!MOV ebx,eax
!MOV ecx,eax
!AND eax,$FF
!MOV dword[p.v_r4],eax
!AND ebx,$FF00
!MOV dword[p.v_g4],ebx
!AND ecx,$FF0000
!MOV dword[p.v_b4],ecx
;pure knows well how to do this
Protected r.l = r1 * f00 + r2 * f10 + r3 * f01 + r4 * f11
Protected g.l = g1 * f00 + g2 * f10 + g3 * f01 + g4 * f11
Protected b.l = b1 * f00 + b2 * f10 + b3 * f01 + b4 * f11
!MOV eax,dword[p.v_r]
!MOV ebx,dword[p.v_g]
!MOV ecx,dword[p.v_b]
;one trick is to let triplets at the same place to avoid shifting
!AND eax,$FF
!AND ebx,$FF00
!AND ecx,$FF0000
!OR eax,ebx
!OR eax,ecx
!MOV ebx,dword[p.v_Mem2Temp]
!MOV dword[ebx],eax
Else
!MOV ebx,dword[p.v_Mem2Temp]
!XOR eax,eax
!MOV dword[ebx],eax
EndIf
Mem2Temp + 4
x1 + Cos
y1 + Sin
Next
Next
; On crée la nouvelle image
NewImageID = CreateImage(#PB_Any, bmi2\bmiHeader\biWidth, bmi2\bmiHeader\biHeight)
Hdc = CreateCompatibleDC_(GetDC_(ImageID(NewImageID)))
If Hdc
SetDIBits_(Hdc, ImageID(NewImageID), 0, bmi2\bmiHeader\biHeight, Mem2, @bmi2, #DIB_RGB_COLORS) ; on envoie la liste dans l'image
ReleaseDC_(0, Hdc)
EndIf
FreeMemory(Mem2)
EndIf
FreeMemory(Mem)
EndIf
ProcedureReturn NewImageID
EndProcedure
CreateImage(0,GetSystemMetrics_(#SM_CXSCREEN),GetSystemMetrics_(#SM_CYSCREEN))
DC = StartDrawing(ImageOutput(0))
BitBlt_(DC,0,0,ImageWidth(0),ImageHeight(0),GetDC_(GetDesktopWindow_()),0,0,#SRCCOPY )
StopDrawing()
X = RotateImageEx2(ImageID(0),90)
If PrintRequester()
If StartPrinting("Copie d'écran")
LoadFont(1, "Arial", 100)
If StartDrawing(PrinterOutput())
DrawingFont(FontID(1))
Lg = PrinterPageHeight()-200
LgP = Lg/ImageHeight(X)*ImageWidth(X)
XL = (PrinterPageWidth()-LgP) /2
DrawText(Lg/2 - 500 , 100, "Copie d'écran")
DrawImage(ImageID(X), XL, 100, LgP, Lg)
StopDrawing()
EndIf
StopPrinting()
EndIf
EndIf