Saving a BMP-part of resources to Disk ? => SOLVED

Saving a BMP-part of resources to Disk ? => SOLVED

Postby ukoenig » Mon Dec 08, 2008 11:58 pm

Hello,

Is it possible to save a resized BMP from resource to Disk ?
I need this for the new xBrowse-options, to paint gradient-bmp's
and save them to disk for use as background-display ( streched to the xBrowse data-erea).

Image

I know, there have been some questions about BMP-saving.

I use for display :

Code: Select all  Expand view

// Gradient-Resource
// -----------------------------------------------------------
REDEFINE BITMAP oBmp30  ID 130 ADJUST RESOURCE "Blanc"  OF oFld:aDialogs[8]
oBmp30:bPainted := { |hDC|DRAW_GRAD( oBMP30, nDIRECTION, nGRADIENT1, nGRADIENT2, ;
nGRADMOVE, nValue1, nValue2 ) }

// Solved, calling < oBMP30:SaveToBmp( "Test.bmp" ) > from a Button
// after resizing.
// --------------------------------------------------------------------------------
REDEFINE BUTTONBMP oBtn24  ID 30 OF oFld:aDialogs[8] ;
ACTION  ( oBMP30:SaveToBmp( "Test.bmp" ) ) ;
BITMAP "Write1" PROMPT "              &Save and Preview" TEXTRIGHT
oBtn24:cToolTip =  { "Click the Button" + CRLF + ;
                                "for information","2. Gradient-Color", 1, CLR_BLACK, 14089979 }


//-------------  GRADIENT HOR / VERT -----------

FUNCTION DRAW_GRAD( oBitmap, nDirection,nVColor, nBColor, nMove, nVERT, nHORZ )
LOCAL aGrad := { { nMove, nVColor, nBColor },{ nMove, nBColor, nVColor } }
LOCAL aRect := GETCLIENTRECT( oBitmap:hWnd )
LOCAL oNewBrush, hDC := oBitmap:GETDC()

newHORZ  := (aRect[3] / 100) * nHORZ
newVERT  := (aRect[4] / 100) * nVERT

IF nDirection = 1
   DEFINE BRUSH oNewBrush COLOR ;
   GradientFill( hDC,0,0, newHORZ, newVERT, aGrad, .T. )
ELSE
   DEFINE BRUSH oNewBrush COLOR ;
   GradientFill( hDC,0,0, newHORZ, newVERT, aGrad, .F. )
ENDIF

FillRect( hDC, aRect, oNewBrush:hBrush )

// --------------------------
//  Save to Disk solved !!!
// --------------------------

oBitmap:ReleaseDC()
RELEASE BRUSH oNewbrush

RETURN NIL


Regards
Uwe :lol:
Last edited by ukoenig on Wed Dec 10, 2008 10:41 am, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Changing Resource-format

Postby ukoenig » Tue Dec 09, 2008 3:14 pm

Hello,

I changed some lines using < oBMP30:SaveToBmp( "Gradient1.bmp" ) >
It works, but the dimension of the saved BMP is allways the dimension
of the resource.

Image

I think, before saving, oBMP30 has to be resized to the Gradient-format.
I tested something like : oBMP30:Resize(.......,
but it doesn't work.

METHOD Resize( nType, nWidth, nHeight ) ???
I couldn't find any values for < nType > to use
-----------------------------------------------------
After saving the BMP, i have to resize back to the old values ( resource ).

Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Saving Resource-part to Disk

Postby ukoenig » Wed Dec 10, 2008 10:44 am

Hello,

After some more tests, I solved the problem :
Painting a gradient on a resource, resize it and save the result to disk.
It has to be done in a different way, as I started with.

How to do it :

Image

Code: Select all  Expand view

// Resource = 250 * 250 Pixel = 100 %
// Start-Values for new Brush :
//  nGRADVERT = 100, nGRADHORZ = 100
// nDIRECTION = Horizontal or Vertical
// nGRADIENT1, nGRADIENT2 = Gradient-Colors
// nGRADMOVE = Gradient-Color - position
// Changing the Sliders ( % ) must change the size of the Resource
// BEFORE !!! the new Brush is painted !

// GRADIENT - Resource
// ----------------------------------------------------------------------------------
REDEFINE BITMAP oBmp30  ID 130 ADJUST RESOURCE "Blanc"  OF
oFld:aDialogs[8]
oBmp30:bPainted := { |hDC|  newHORZ  := 2.5 * nGRADHORZ, ;
newVERT  := 2.5 * nGRADVERT, ;
oBMP30:nWidth  := newHORZ,  oBMP30:nHeight  := newVERT, ;
DRAW_GRAD( oBMP30, nDIRECTION, nGRADIENT1, nGRADIENT2, ;
         nGRADMOVE ) }

// --------------- The SAVE- Button ---------------------

// save as
// ---------
REDEFINE GET oGRADBMP VAR GRADBMP  ID 150  OF oFld:aDialogs[8]  UPDATE

REDEFINE BUTTONBMP oBtn24  ID 30 OF oFld:aDialogs[8] ;
ACTION  ( oGradBmp:Refresh(), ;
                  SAVETOBMP := ALLTRIM(GRADBMP) + ".BMP", ;
                  oBMP30:SaveToBmp( "&SAVETOBMP" ) ) ;
BITMAP "Write1" PROMPT "              &Save and Preview" TEXTRIGHT
oBtn24:cToolTip =  { "Click the Button" + CRLF + ;
      "for information","2. Gradient-Color", 1, CLR_BLACK, 14089979 }

// ----------------- Horizontal %-Slider ---------------------

REDEFINE SLIDER oSLIDER1 VAR nGRADHORZ OF oFld:aDialogs[8] ID 710;
HORIZONTAL ;
RIGHT DIRECTION ;
RANGE 0, 100 ;
ON CHANGE ( oGRADHORZ:Refresh(), oBMP30:Refresh() ) ;
COLORS 128, 15977281, 128 ;
MARKS 11 ;
UPDATE

REDEFINE GET oGRADHORZ   VAR   nGRADHORZ  ID 715 PICTURE "999" OF oFld:aDialogs[8]  UPDATE ;
VALID ( ( oGRADHORZ:Refresh(), oSlider1:Set(nGRADHORZ *10), oSlider1:Refresh(), oBMP30:Refresh() ), .T. )

// ----------------- Vertical %-Slider ---------------------

REDEFINE SLIDER oSLIDER2  VAR  nGRADVERT OF oFld:aDialogs[8] ID 700;
VERTICAL ;
RIGHT DIRECTION ;
RANGE 0, 100 ;
ON CHANGE ( oGRADVERT:Refresh(), oBMP30:Refresh() ) ;
     COLORS 128, 15977281, 128 ;
     MARKS 11 ;
     UPDATE

REDEFINE GET oGRADVERT   VAR   nGRADVERT  ID 705 PICTURE "999" OF oFld:aDialogs[8]  UPDATE ;
VALID ( ( oGRADHORZ:Refresh(), oSlider2:Set(nGRADVERT *10), oSlider1:Refresh(), oBMP30:Refresh() ), .T. )

// ----------------- Color-Move-Slider ---------------------

REDEFINE BUTTONBMP oTitle24  ID 640 OF oFld:aDialogs[8] ;
ACTION MsgAlert("With this Browser, you can move" + CRLF + ;
   "the Gradient-Color","Gradient-Color" ) ;
BITMAP "Info1" PROMPT "   Move Color" TEXTRIGHT
oTITLE24:cToolTip =  { "Click the Button" + CRLF + ;
           "for information","Gradient-Color", 1, CLR_BLACK, 14089979 }

REDEFINE SLIDER  oSLIDER3  VAR  nMOVE OF oFld:aDialogs[8] ID 720;
HORIZONTAL ;
RIGHT DIRECTION ;
RANGE 0, 1 ;
ON CHANGE ( IIF( nMove = 0, nGRADMOVE := 0.01, NIL ), ;
   oGRADMOVE:Refresh(), oBMP30:Refresh() ) ;
   COLORS 128, 15977281, 128 ;
   MARKS 11 ;
   UPDATE

REDEFINE GET oGRADMOVE     VAR   nGRADMOVE  ID 725 PICTURE "9.99" OF oFld:aDialogs[8]  UPDATE ;
VALID ( ( oGRADMOVE:Refresh(), oSlider3:Set(nGRADMOVE *10), ;
oSlider3:Refresh(), oBMP30:Refresh() ), .T. )


//-------------  GRADIENT Paint-Function HOR / VERT -----------

FUNCTION DRAW_GRAD( oBitmap, nDirection,nVColor, nBColor, nMove )
LOCAL aGrad := { { nMove, nVColor, nBColor }, ;
         { nMove, nBColor, nVColor } }
LOCAL oNewBrush, hDC := oBitmap:GETDC()

IF nDirection = 1
   DEFINE BRUSH oNewBrush COLOR ;
   GradientFill( hDC,0,0, newVERT, newHORZ, aGrad, .T. )
ELSE
   DEFINE BRUSH oNewBrush COLOR ;
   GradientFill( hDC,0,0, newHORZ, newVERT, newHORZ, aGrad, .F. )
ENDIF

PalBmpDraw( hDC, 0, 0, oNewBrush:hBrush, , newHORZ, newVERT )

oBitmap:ReleaseDC()
RELEASE BRUSH oNewbrush

RETURN NIL



Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests