Re: [Windows] 2DDrawing Befehle mit AntiAliasing durch GDI+
Verfasst: 11.07.2011 12:14
Cool, vielen Dank
.

Das deutsche PureBasic-Forum
https://www.purebasic.fr/german/
dito no.2DarkDragon hat geschrieben:Cool, vielen Dank.
Code: Alles auswählen
Enumeration
#Window : #Gadget : #Image
EndEnumeration
XIncludeFile "gDrawing.pbi"
gInit()
CreateImage(#Image, 256, 512, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(#Image))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
For Size = 1 To 24
DrawText(10, Size*Size*0.8, Str(Size), $FF000000)
Next
Box(50, 0, 100, 512, $FFF0A050)
StopDrawing()
gStartDrawing(ImageOutput(#Image))
For Size = 1 To 24
gSetFont("Arial", Size)
gDrawText(60, Size*Size*0.8, "Hallo", $FF000000)
Next
gStopDrawing()
OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ImageGadget(#Gadget, 0, 0, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Hier gleiches Ergebnis:STARGÅTE hat geschrieben:Hat noch jemand diesen Fehler?
Code: Alles auswählen
XIncludeFile "gDrawing.pbi"
Procedure ScaleDemo(scaleX.f, scaleY.f)
img = CreateImage(#PB_Any,400,300,24)
If gStartDrawing( ImageOutput(img) )
gClear( RGBA($AA,$AA,$AA,$FF) )
gScaleAt(200,150,scaleX,scaleY)
gStartTransform()
gDrawingMode( #PB_2DDrawing_Outlined )
;
; gEllipse rotieren
;
For i = 0 To 90 Step 10
gRotateAt(50,50,i) : gEllipse(50,50,50,15) : gResetTransform()
Next i
gStopTransform()
gStopDrawing()
EndIf
ProcedureReturn img
EndProcedure
If gInit()
mainWin = OpenWindow(#PB_Any,0,0,800,600,"gDrawing scale demo",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(#PB_Any, 0, 0,400,300,ImageID( ScaleDemo( 1, 1) )) ; normal
ImageGadget(#PB_Any,400, 0,400,300,ImageID( ScaleDemo(-1, 1) )) ; gespiegelt um Y-Achse
ImageGadget(#PB_Any, 0,300,400,300,ImageID( ScaleDemo( 1,-1) )) ; gespiegelt um X-Achse
ImageGadget(#PB_Any,400,300,400,300,ImageID( ScaleDemo(-1,-1) )) ; gespiegelt um X- und Y-Achse
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
gEnd()
EndIf
Code: Alles auswählen
EnableExplicit
XIncludeFile "gDrawing.pbi"
Procedure MirrorImage(original,x,y)
Protected copy, w, h
copy = CreateImage(#PB_Any,ImageWidth(original),ImageHeight(original),24)
;copy = CopyImage(original,#PB_Any)
If copy
w = ImageWidth(original)
h = ImageHeight(original)
If gStartDrawing( ImageOutput(copy) )
gSetPenImage( ImageID(original) ,#WrapModeTileFlipXY)
If x : gSetPenOrigin(0,h) : EndIf
If y : gSetPenOrigin(w,0) : EndIf
gBox(0,0,w,h)
gStopDrawing()
EndIf
EndIf
ProcedureReturn copy
EndProcedure
Procedure DrawShearedImage(img,x.f,y.f,ShearX.f,ShearY.f)
gStartTransform()
gShearAt(x,y,ShearX,ShearY)
gSetPenImage( ImageID(img) )
gSetPenOrigin(x,y)
gBox(x,y,ImageWidth(img),ImageHeight(img))
gStopTransform()
EndProcedure
Define pbLogo, pbLogoMirror, img
pbLogo = LoadImage(#PB_Any,#PB_Compiler_Home+"Examples\Sources\Data\PureBasicLogo.bmp")
If Not pbLogo : MessageRequester("ERROR","Unable to load PureBasic logo!") : End : EndIf
If gInit()
pbLogoMirror = MirrorImage(pbLogo,1,0)
img = CreateImage(#PB_Any,800,600)
If gStartDrawing( ImageOutput(img) )
DrawImage(ImageID(pblogo),100,100)
DrawShearedImage(pbLogoMirror,100,100+ImageHeight(pbLogo),0.8,0)
gStopDrawing()
EndIf
OpenWindow(#PB_Any,0,0,800,600,"gDrawing gShear",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(#PB_Any,0,0,800,600,ImageID( img ),#PB_Image_Border ) ; normal
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
gEnd()
EndIf
Schaue ich morgen früh. Jetzt muß ich gleich auf Arbeit.STARGÅTE hat geschrieben:Bei mir funktioneirt gDrawText() irgendwie garnicht, oder nur sehr schlecht:
[...]
Kannst du Danilo oder jemand anderes mir sagen, wie ich das beheben kann?
Das Problem liegt an dem (in gStartDrawing() vordefinierten) Wert des TextAntialiasingModes.STARGÅTE hat geschrieben:Kannst du Danilo oder jemand anderes mir sagen, wie ich das beheben kann?
Code: Alles auswählen
Protected *hdc = GetDC_(#Null);
AlignedFontSize = (FontSize * GetDeviceCaps_(*hdc, #LOGPIXELSY) / 72)
ReleaseDC_(#Null, *hdc)
Code: Alles auswählen
; --- einfügen in Zeile 331
Global __currentDC.i ; <--- neue Variable, um DC zwischen zu speichern
Code: Alles auswählen
Procedure gStartDrawing( out )
Protected hDC
hDC = StartDrawing(out)
If Not hDC : ProcedureReturn 0 : EndIf
GdipCreateFromHDC_(hDC ,@__graphics)
If Not __graphics
StopDrawing()
ProcedureReturn 0
EndIf
__drawingMode = #PB_2DDrawing_Default
__lineCapStart = #LineCapFlat
__lineCapEnd = #LineCapFlat
__currentTextAntialiasingMode = #TextAntialiasMode_AntiAlias
gSetPen(RGBA($FF,$FF,$FF,$FF),1.0)
gSetFont("Arial",12,#PB_Font_Default)
GdipCreateMatrix_(@__transformMatrix)
GdipSetSmoothingMode_ (__graphics,#SmoothingModeAntiAlias)
GdipSetCompositingMode_ (__graphics,#CompositingModeSourceOver)
GdipSetCompositingQuality_(__graphics,#CompositingQualityGammaCorrected)
GdipSetInterpolationMode_ (__graphics,#InterpolationModeHighQualityBicubic)
GdipSetPixelOffsetMode_ (__graphics,#PixelOffsetModeNone)
__currentDC = hDC ; <--- buffering DC
ProcedureReturn hDC
EndProcedure
Procedure gStopDrawing()
If __graphics : GdipDeleteGraphics_( __graphics ) : __graphics = 0 : EndIf
If __currentPen : GdipDeletePen_ ( __currentPen ) : __currentPen = 0 : EndIf
If __currentBrush : GdipDeleteBrush_ ( __currentBrush ) : __currentBrush = 0 : EndIf
If __currentFont : GdipDeleteFont_ ( __currentFont ) : __currentFont = 0 : EndIf
If __transformMatrix : GdipDeleteMatrix_ (__transformMatrix) : __transformMatrix = 0 : EndIf
StopDrawing()
__currentDC = #False ; <--- Clearing buffered DC
EndProcedure
Procedure gSetFont( FontName$="Arial", FontSize.f=12, FontStyle.l = 0)
Protected fs, *fontFamily, *font, *fontName
If FontStyle = #PB_Font_Default : FontStyle = 0: EndIf
If FontStyle & #PB_Font_Bold : fs | 1 : EndIf
If FontStyle & #PB_Font_Italic : fs | 2 : EndIf
If FontStyle & #PB_Font_Underline : fs | 4 : EndIf
If FontStyle & #PB_Font_StrikeOut : fs | 8 : EndIf
If Not __currentDC
Protected *hdc = GetDC_(#Null);
AlignedFontSize = (FontSize * GetDeviceCaps_(*hdc, #LOGPIXELSY) / 72)
ReleaseDC_(#Null, *hdc)
Else
AlignedFontSize = (FontSize * GetDeviceCaps_(__currentDC, #LOGPIXELSY) / 72)
EndIf
CompilerIf #PB_Compiler_Unicode = 0
Protected len = Len(FontName$)
Protected tmp$ = Space(len*2+2)
PokeS(@tmp$,FontName$,-1,#PB_Unicode)
*fontName = @tmp$
CompilerElse
*fontName = @FontName$
CompilerEndIf
If GdipCreateFontFamilyFromName_(*fontName,0, @*fontFamily)
If GdipGetGenericFontFamilySansSerif_(@*fontFamily)
If GdipGetGenericFontFamilySerif_(@*fontFamily)
If GdipGetGenericFontFamilyMonospace_(@*fontFamily)
ProcedureReturn
EndIf
EndIf
EndIf
EndIf
If Not GdipCreateFont_(*fontFamily,FontSize,fs,2,@*font)
If __currentFont : GdipDeleteFont_(__currentFont) : EndIf
__currentFont = *font
GdipDeleteFontFamily_(*fontFamily)
EndIf
EndProcedure
Code: Alles auswählen
Enumeration
#Window : #Gadget : #Image
EndEnumeration
XIncludeFile "gDrawing.pbi"
gInit()
CreateImage(#Image, 256, 512, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(#Image))
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
For Size = 1 To 24
DrawText(10, Size*Size*0.8, Str(Size), $FF000000)
Next
Box( 50, 0, 100, 512, $FFF0A050)
Box(150, 0, 100, 512, $FFF050a0)
StopDrawing()
For Size = 1 To 24
LoadFont(0, "Arial", Size)
gStartDrawing(ImageOutput(#Image))
gSetFont("Arial", Size)
gDrawText(60, Size*Size*0.8, "Hallo", $FF000000)
DrawingFont(FontID(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(160, Size*Size*0.8, "Hallo", $FF000000)
gStopDrawing()
Next
OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ImageGadget(#Gadget, 0, 0, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Code: Alles auswählen
Enumeration
#Window : #Gadget : #Image
EndEnumeration
XIncludeFile "gDrawing.pbi"
If gInit()
CreateImage(#Image, 256, 512, 24);|#PB_Image_Transparent)
If gStartDrawing(ImageOutput(#Image))
gSetTextAntialiasMode(#TextAntialiasMode_Antialias)
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent)
Box(50, 0, 100, 512, $FFF0A050)
For Size = 1 To 24
DrawText(10, Size*Size*0.8, Str(Size), $FF000000)
gSetFont("Arial", Size)
gDrawText(60, Size*Size*0.8, "Hallo", $FF000000)
Next
gStopDrawing()
EndIf
OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Image", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ImageGadget(#Gadget, 0, 0, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
gEnd()
EndIf
Code: Alles auswählen
gSetPen($FF000000, 100)
gLineXY(100,100, 200, 100)