| Author | Topic: How to extract a part of a xbpBitmap | |
|---|---|---|
![]() | Jack Duijf | How to extract a part of a xbpBitmap on Fri, 04 May 2012 19:53:44 +0200 Hello,
I load a image from a existing jpg file into a xbpBitmap.
Now a want to save just a small part of that image into a new file.
How can i do this?
oBitmap := xbpBitmap():New()
oBitmap:LoadFile("MyImage.jpg")
? oBitmap:xSize --> 640
? oBitMap:ySize --> 480
SavePartOfBitmapAsFile(oBitmap,{160,120},{320,240},"MyClipedImage.jpg")
oBitMap:Destroy()
oBitmap := xbpBitmap():New()
oBitmap:LoadFile("MyClipedImage.jpg")
? oBitmap:xSize --> 320
? oBitMap:ySize --> 240
Procedure SavePartOfBitmapAsFile(oBitmap,aPos,aSize,cFileName)
How to do this ?
Return
Suggestions are welcome.
Regards,
Jack Duijf |
![]() | James Loughner | Re: How to extract a part of a xbpBitmap on Fri, 04 May 2012 17:53:45 -0400 GraBitBlit it to anouter bitmap object then save that
Jim
On 05/04/2012 01:53 PM, Jack Duijf wrote:
> Hello,
>
> I load a image from a existing jpg file into a xbpBitmap.
> Now a want to save just a small part of that image into a new file.
> How can i do this?
>
> oBitmap := xbpBitmap():New()
> oBitmap:LoadFile("MyImage.jpg")
> ? oBitmap:xSize --> 640
> ? oBitMap:ySize --> 480
> SavePartOfBitmapAsFile(oBitmap,{160,120},{320,240},"MyClipedImage.jpg")
> oBitMap:Destroy()
> oBitmap := xbpBitmap():New()
> oBitmap:LoadFile("MyClipedImage.jpg")
> ? oBitmap:xSize --> 320
> ? oBitMap:ySize --> 240
>
> Procedure SavePartOfBitmapAsFile(oBitmap,aPos,aSize,cFileName)
>
> How to do this ?
>
> Return
>
> Suggestions are welcome.
> Regards,
> Jack Duijf
> |
![]() | AUGE_ OHR | Re: How to extract a part of a xbpBitmap on Sat, 05 May 2012 19:37:32 +0200 hi,
> SavePartOfBitmapAsFile(oBitmap,{160,120},{320,240},"MyClipedImage.jpg")
>
> Procedure SavePartOfBitmapAsFile(oBitmap,aPos,aSize,cFileName)
you need a Function |
![]() | AUGE_ OHR | Re: How to extract a part of a xbpBitmap on Sat, 05 May 2012 19:44:36 +0200 hm ... just saw that my Solution is not excat your Problem
LOCAL aRectNew := { aPos[1], aPos[2], nSizeX, nSizeY }
LOCAL aRectSrc := { 0, 0, 0, 0 }
while you want a Part of Source you must "fill"
aRectSrc = { aPos[1], aPos[2], nSizeX, nSizeY }
and new Result is
aRectNew := { 0, 0, nSizeX, nSizeY }
greetings by OHR
Jimmy |



greetings by OHR
Jimmy
*** Code ***
oNewBMP := BMPGraBitBlt( oBitmap,aPos, aSize )
FUNCTION BMPGraBitBlt( oBMP,aPos, aSize )
LOCAL oOutBMP := XBPBITMAP() :new() :create()
LOCAL oTargetPS := XBPPRESSPACE() :new() :create()
LOCAL oSourcePS := XBPPRESSPACE() :new() :create()
LOCAL nSizeX := aSize[ 1 ]
LOCAL nSizeY := aSize[ 2 ]
LOCAL aRectNew := { aPos[1], aPos[2], nSizeX, nSizeY }
LOCAL aRectSrc := { 0, 0, 0, 0 }
LOCAL nClr
LOCAL nBits
LOCAL nPlanes
IF VALTYPE( oBMP ) = "O" .AND. oBMP:isDerivedFrom( "XBPBITMAP" )
aRectSrc[ 3 ] := oBMP:xSize
aRectSrc[ 4 ] := oBMP:ySize
nBits := oBMP:bits
nPlanes := oBMP:planes
nClr := oBMP:transparentClr
oBMP:presSpace( oSourcePS )
oOutBMP:presSpace( oTargetPS )
oOutBMP:transparentClr := nClr
oOutBMP:make( nSizeX, nSizeY, nPlanes, nBits )
IF aRectSrc[ 3 ] > aRectNew[ 3 ] .OR. aRectSrc[ 4 ] > aRectNew[ 4 ]
Source is bigger than Result
need 6th Parameter nCompress ?
GraBitBlt( oTargetPS, oSourcePS, aRectNew, aRectSrc, ,
GRA_BLT_BBO_OR )
ELSE
Source is smaller than Result
only 5th Parameter nRasterOP
GraBitBlt( oTargetPS, oSourcePS, aRectNew, aRectSrc,
GRA_BLT_ROP_SRCCOPY )
ENDIF
oBMP:destroy()
ENDIF
RETURN oOutBMP
eof
*