Seite 1 von 1
Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 11:53
von Rudolf
Hallo,
möchte einen Ausschnitt aus einem Bitmap, bekomme aber immer nur ein leeres (schwarzes) Bitmap zurück, was stimmt nicht ?
Grüße
Rudolf
Code: Alles auswählen
function cropimage(cBuffer,aFields,x)
******************************************************************
local oBmp,nBSizex := 0,nBSizeY := 0,oPS
if substr(cBuffer,1,2) = "BM"
cBuffer := substr(cBuffer,15)
endif
oPS := XbpPresSpace():New():Create()
oBmp := xbpBitmap():new():create(oPS)
oBmp:setbuffer(cBuffer)
nBSizex := oBmp:xSize
nBSizeY := oBmp:ySize
oBmp := GraSaveScreen( oPS, {100,100},{30,50})
oBmp:savefile("test.bmp")
return .t.
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )
******************************************************************
LOCAL oBitmap := XbpBitmap():new():create( oSourcePS )
LOCAL oTargetPS := XbpPresSpace():new():create()
LOCAL aSourceRect[4], aTargetRect
aSourceRect[1] := aSourceRect[3] := aPos[1]
aSourceRect[2] := aSourceRect[4] := aPos[2]
aSourceRect[3] += aSize[1]
aSourceRect[4] += aSize[2]
aTargetRect := {0, 0, aSize[1], aSize[2]}
oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )
GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )
RETURN oBitmap
Re: Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 12:45
von Rolf Ramacher
Hallo Rudolf,
ich mache das etwas anders. ich hinterlege das Bitmap zu einem pushbutton
Code: Alles auswählen
oBmp:= XbpBitmap():new()
oBmp:load(nil,2001)
oBmp:create(oDlg)
oXbp := XbpPushButton():new( drawingArea, , aBtmPos, {500,400}, { { XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } } )
oXbp:caption := (oBmp)
oXbp:create()
oXbp:activate := {|| Gather( aEditControls ), .f. }
Re: Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 17:37
von Wolfgang Ciriack
Es ist schön, dass du versuchst zu Helfen, aber bitte bitte Rolf, lies vorher die Frage.
Re: Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 17:39
von Manfred
ach, Rolf ist ne köllsche Frohnatur. Sein Motto: Dabeisein ist alles
Re: Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 19:18
von Rudolf
Hallo Leute,
der Wille zählt fürs Werk, schön dass es diese Forum gibt !
Grüße
Rudolf
Re: Bitmap beschneiden
Verfasst: Mi, 21. Sep 2016 22:06
von AUGE_OHR
Rudolf hat geschrieben:möchte einen Ausschnitt aus einem Bitmap,
Code: Alles auswählen
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )
...
aSourceRect[1] := aSourceRect[3] := aPos[1]
aSourceRect[2] := aSourceRect[4] := aPos[2]
aSourceRect[3] += aSize[1]
aSourceRect[4] += aSize[2]
aTargetRect := {0, 0, aSize[1], aSize[2]}
wenn die Grösse von aSourceRect = aTargetRect ist es 1:1 und kein Ausschnitt.
Rudolf hat geschrieben:bekomme aber immer nur ein leeres (schwarzes) Bitmap zurück, was stimmt nicht ?
du hast doch wohl ein Bitmap Object also ist die FUNCTION cropimage() überflüssig.
zum vergrössern/verkleinern eines Bitmap Object gehe ich so vor
Code: Alles auswählen
FUNCTION BMP2BMP( oBMP, aXbpSize, oPS )
LOCAL oHuge
LOCAL oTiny
LOCAL oRet
LOCAL nBits
LOCAL nPlanes
IF aXbpSize[ 2 ] > 0
oHuge := oBMP
nBits := oBMP:bits
nPlanes := oBMP:planes
IF oPS = NIL
oPS := XBPPRESSPACE() :new() :Create()
ENDIF
//Create a small bitmap to fit in our XbpStatic
oTiny := XBPBITMAP() :New() :Create()
IF nBits > 1 .OR. nPlanes > 1
oTiny:Make( aXbpSize[ 1 ], aXbpSize[ 2 ], nPlanes, nBits )
ELSE
oTiny:Make( aXbpSize[ 1 ], aXbpSize[ 2 ] )
ENDIF
oTiny:transparentClr := oBMP:getDefaultBGColor()
oTiny:presSpace( oPS )
//Copie and resize the huge bitmap to the small bitmap
oHuge:Draw( oPS, { 0, 0, aXbpSize[ 1 ], aXbpSize[ 2 ] }, ; // aTargetRect
{ 0, 0, aXbpSize[ 1 ], aXbpSize[ 2 ] }, ; // aSourceRect
, ; // nRasterOP
GRA_BLT_BBO_IGNORE ) // nCompress
oRet := oTiny
ELSE
oRet := oBMP
ENDIF
RETURN oRet
wenn es nur ein (Source) Ausschnitt sein soll musst du aSourceRect anpassen.
Re: Bitmap beschneiden
Verfasst: Do, 22. Sep 2016 7:28
von Rudolf
Hallo Jimmy,
danke, hab oBmp:draw() jetzt verstanden, funktioniert im Prinzip, nur ist das Ergebnis noch nicht ganz richtig, was könnte da falsch sein ?
Grüße
Rudolf
Code: Alles auswählen
function croptest()
******************************************************************
local oPDF,oPS,oBmp,nOk,cBuffer,nBits,nPlanes,oTiny,oPS2
local aSize := {300,100},aPos := {120,80}
WITH OBJECT ( oPdf := TQuickPdf():New() )
nOk := .:LoadFromFile("test.pdf")
cBuffer := .:RenderPagetoString(150,1,0)
if substr(cBuffer,1,2) = "BM"
cBuffer := substr(cBuffer,15)
endif
oPS := XbpPresSpace():New():Create()
oBmp := xbpBitmap():new():create(oPS)
oBmp:setbuffer(cBuffer)
nBSizex := oBmp:xSize
nBSizeY := oBmp:ySize
nBits := oBMP:bits
nPlanes := oBMP:planes
oPS2 := XBPPRESSPACE() :new() :Create()
//Create a small bitmap to fit in our XbpStatic
oTiny := XBPBITMAP() :New() :Create()
IF nBits > 1 .OR. nPlanes > 1
oTiny:Make( aSize[ 1 ], aSize[ 2 ], nPlanes, nBits )
ELSE
oTiny:Make( aSize[ 1 ], aSize[ 2 ] )
ENDIF
oTiny:transparentClr := oBMP:getDefaultBGColor()
oTiny:presSpace( oPS2 )
//Copie and resize the huge bitmap to the small bitmap
oBmp:Draw( oPS2, { 0, 0, aSize[ 1 ], aSize[ 2 ] }, ; // aTargetRect
{ 400,400, aSize[ 1 ], aSize[ 2 ] }, ; // aSourceRect
, ; // nRasterOP
GRA_BLT_BBO_IGNORE ) // nCompress
oTiny:savefile("crop.bmp")
.:Destroy()
END WITH
return .t.
Re: Bitmap beschneiden
Verfasst: Do, 22. Sep 2016 7:33
von brandelh
Der Ursprungspunkt liegt bei Xbase++ ja links unten (normal) deine Bitmap sieht aus, als ob sie 180° verdreht bzw. horizontal gespiegelt wurde. Oben und unten tauschen ?
Re: Bitmap beschneiden
Verfasst: Do, 22. Sep 2016 8:08
von Rudolf
Hallo Hubert,
danke, hast Recht, ich hab übersehen dass ich nicht ein Array mit Größe benötige sondern die Koordinaten.
Grüße
Rudolf