Hi Nic, ...
wenn es Dir bei Deiner Anfrage um eine möglichst hohe Geschwindigkeit ging - da hätte ich (natürlich) keine Lösung für.
Wenn es Dir aber nur um die Einfachheit ging (also alles mit einem bzw. zwei Befehl machen zu können) so hätte ich da zwei kleine Procs für Dich:
Code: Alles auswählen
EnableExplicit
Structure ImageClip
XPos.l
YPos.l
Width.l
Height.l
ImgID.i
EndStructure
Procedure InitClipImage()
Global NewList ClippedImage.ImageClip()
Global ClipImageInitialized = #True
EndProcedure
Procedure ClipImage(ImgID, XPos, YPos, Width, Height)
If Not ClipImageInitialized : InitClipImage() : EndIf
Protected ActImgID = #PB_Any
ForEach ClippedImage()
If ImgID = ClippedImage()\ImgID
ActImgID = ImgID
Break
EndIf
Next
If ActImgID = #PB_Any
AddElement(ClippedImage())
EndIf
ClippedImage()\XPos = XPos
ClippedImage()\YPos = YPos
ClippedImage()\Width = Width
ClippedImage()\Height = Height
ClippedImage()\ImgID = ImgID
EndProcedure
Procedure DrawClippedImage(ImgID, XPos, YPos, Width=#PB_Ignore, Height=#PB_Ignore, ZoomMode=#PB_Image_Raw)
Protected ActImgID = ImgID, DummyImg.i = #PB_Any
If ClipImageInitialized
ActImgID = #PB_Any
ForEach ClippedImage()
If ImgID = ClippedImage()\ImgID
ActImgID = ImgID
Break
EndIf
Next
If ActImgID <> #PB_Any
DummyImg = GrabImage(ImgID, #PB_Any, ClippedImage()\XPos, ClippedImage()\YPos, ClippedImage()\Width, ClippedImage()\Height)
If Not DummyImg : ProcedureReturn #False : EndIf
If Width <> #PB_Ignore And Height <> #PB_Ignore
ResizeImage(DummyImg, Width, Height, ZoomMode)
ElseIf Width <> #PB_Ignore
ResizeImage(DummyImg, Width, ClippedImage()\Height, ZoomMode)
ElseIf Height <> #PB_Ignore
ResizeImage(DummyImg, ClippedImage()\Width, Height, ZoomMode)
EndIf
ActImgID = DummyImg
ElseIf (Width <> #PB_Ignore And Width <> ImageWidth(ImgID)) Or (Height <> #PB_Ignore And Height <> ImageHeight(ImgID))
DummyImg = CopyImage(ImgID, #PB_Any)
If Not DummyImg : ProcedureReturn #False : EndIf
If Width <> #PB_Ignore And Height <> #PB_Ignore
ResizeImage(DummyImg, Width, Height, ZoomMode)
ElseIf Width <> #PB_Ignore
ResizeImage(DummyImg, Width, ClippedImage()\Height, ZoomMode)
ElseIf Height <> #PB_Ignore
ResizeImage(DummyImg, ClippedImage()\Width, Height, ZoomMode)
EndIf
ActImgID = DummyImg
Else
ActImgID = ImgID
EndIf
EndIf
DrawImage(ImageID(ActImgID), XPos, YPos)
If IsImage(DummyImg) : FreeImage(DummyImg) : EndIf
EndProcedure
; >>>>>>>>>> nachfolgend ein kleiner Beispiel-Code <<<<<<<<<<<<<<<
Define n
If CreateImage(0,200,200)
If StartDrawing(ImageOutput(0))
For n = 1 To 100
Circle(Random(200), Random(200), Random(20), Random($ffffff))
Next n
StopDrawing()
EndIf
EndIf
If OpenWindow(0,0,0,820,765,"Clipped Image Test",#PB_Window_ScreenCentered | #PB_Window_SystemMenu)
If StartDrawing(WindowOutput(0))
DrawImage(ImageID(0),0,0)
For n = 1 To 8
ClipImage(0,Random(130),Random(130), Random(30)+30, Random(30)+30)
DrawClippedImage(0,(n-1)*103,230) ; Ohne Angabe von Width & Height wird der geclippte Bereich in Originalgröße gezeichnet
DrawClippedImage(0,(n-1)*103,360,100,100) ; der geclippte Bereich wird auf 100 x 100 Pixel gezoomed
ClipImage(0,Random(50),Random(50), Random(60)+90, Random(60)+90)
DrawClippedImage(0,(n-1)*103,490) ; s.o.
DrawClippedImage(0,(n-1)*103+20,620,60,60) ; geclippter Bereich wird OHNE Smoothing verkleinert
DrawClippedImage(0,(n-1)*103+20,700,60,60,#PB_Image_Smooth) ; geclippter Bereich wird MIT Smoothing verkleinert
Next n
DrawText(0,210," geclippte Ausschnitte in originaler Clip-Größe")
DrawText(0,340," geclippte Ausschnitte auf 100x100 Pixel gezoomed (beim Zoomen ist smoothing ohne Wirkung)")
DrawText(0,470," (neue) geclippte Ausschnitte in originaler Clip-Größe (diesmal größere Ausschnitte, da nachfolgend verkleinert wird)")
DrawText(0,600," (neue) geclippte Ausschnitte auf 60x60 Pixel verkleinert - OHNE smoothing")
DrawText(0,682," (neue) geclippte Ausschnitte auf 60x60 Pixel verkleinert - MIT smoothing")
StopDrawing()
EndIf
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
EndIf