Using a Jpg instead of a Bitmap for Opening screen Graphics

Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby Rick Lipkin » Sun Nov 18, 2018 6:14 pm

To All

As many of you know I like to create some nice graphics for my application screens .. here is a sample

Image

Unfortunatly, the bitmap images are generally 3-4 mg in size and I would rather use the same image, only in a .Jpg format without having to use FreeImage.dll .. Here is my current code ..

Any suggestions to replace this code to use a ( much smaller ) .Jpg vs a Bitmap in a Mdi environment that uses the PalBmpDraw() function ..

Code: Select all  Expand view


local oBmp,oBMAP,nScr1,nScr2

nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)

DEFINE BITMAP oBMP  FILENAME (cDEFA+"\FMLA.BMP") of oWind   // this is the main screen graphic
DEFINE BITMAP oBMAP FILENAME (cDEFA+"\LOGO.BMP") of oWind  

..
..
..
ACTIVATE WINDOW oWind                                         ;
   MAXIMIZED ;
   ON INIT  ( IF( nSCR1 < 1024, _ResMessage(nSCR1, nSCR2), ),_ChkOwner( oWind,cFirst)); // 560,230
   ON PAINT ( IF( xTEXT = "/NL", ,PalBmpDraw( hDC, 0,0, oBmp:hBitmap,  oBmp:hPalette, nSCR1, nSCR2 )),;
                    PalBmpDraw( hDC, _UpDown(), _RightLeft(), oBMAP:hBitmap, oBMAP:hPalette,305,191 ));
   VALID ( IIF( !lExitPgm, _ExitPgm( .T.,@lExitPgm ) , .F. ))
 



Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2631
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby TimStone » Mon Nov 19, 2018 12:18 am

I use a file lookup, then save the path in a data field. On startup, I grab the file path in a memory variable, then use:
DEFINE BRUSH oWinBrush FILE cScrWin

Then I use:
DEFINE WINDOW oWnd TITLE mlsTitle FROM 0,0 TO 1030, 1740 PIXEL BRUSH oWinBrush MENU oMenu

It works perfectly.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby nageswaragunupudi » Mon Nov 19, 2018 3:25 am

1. We can define Bitmap and Brush with any image file ( jpg, png, tif, ico, bmp ) without the need of freeimage.dll.
2. We can paint any image without first having to define a bitmap object.

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oWnd
   local cJpg  := "c:\fwh\bitmaps\olga1.jpg"

   DEFINE WINDOW oWnd

   oWnd:nWidth    := 700
   oWnd:nHeight   := 500

   ACTIVATE WINDOW oWnd CENTERED ON PAINT ( ;
      oWnd:DrawImage( cJpg, { 0,0,300,235 } ), ;
      oWnd:DrawImage( cJpg, { -135,-105,nil,nil } ) )

return nil
 


Image

oWnd:DrawImage(...)
Param-1: Image file name or Resource name or hBitmap
Param-3: Optional. aRect: Rectangle specifying the position of the image. Default centered. Resiging and repositioning is automatically taken care of.

We can also define a brush using jpg or any other image file. Freeimage.dll is not required.

Code: Select all  Expand view

DEFINE BRUSH oBrush FILE "c:\fwh\bitmaps\olga1.jpg" RESIZE
DEFINE WINDOW oWnd BRUSH oBrush
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10264
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby joseluisysturiz » Mon Nov 19, 2018 4:02 am

Saludos, como puedo hacer para que una imagen de un tamaño X, Y quede centrada en la ventana principal no importando la resolucion del monitor y sin cambiar tamaño de la imagen.?, saludos, gracias... :shock:

GOOGLE TRASLATOR
Greetings, how can I make an image of an X,Y size, and be centered in the main window no matter the resolution of the monitor and without changing the size of the image?, Greetings, thanks... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby nageswaragunupudi » Mon Nov 19, 2018 4:23 am

Code: Select all  Expand view
ON PAINT oWnd:DrawImage( cImage )

This always paints the image at the center of the Window with the original size of the image. Even when you resize the window, the image is always displayed at the center of the window. If the window is resized to a very small size, i.e., less than the original size of the image, then the image is resized to fit the window size.

Let us take another case. The original size of image "fwh\bitmaps\olga1.jpg" is 352x450. Let us assume that we want to reduce the size of the image to half and display at the center.
Code: Select all  Expand view

ON PAINT oWnd:DrawImage( "c:\fwh\bitmaps\olga1.jpg(176x225)"  )
 


Is this what you asked? Or something else?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10264
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby joseluisysturiz » Mon Nov 19, 2018 5:10 am

Mr. RAO, thank you for your quick response ... it's exactly what I wanted. Now I can think of another option, which is the image that adjusts its size to that of the window since it can vary in size depending on the resolution of the monitor ... as it would be in that case.? greetings thank you... :shock:

Mr. RAO, gracias por su rapida respuesta...es exactamente lo que queria. Ahora se me ocurre otra opcion, que sea la imagen la que ajuste su tamaño al de la ventana ya que esta puede variar de tamaño dependiendo de la resolucion del monitor...como seria en ese caso.? saludos, gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby Rick Lipkin » Wed Nov 21, 2018 9:49 pm

Rao

It appears that DrawImage() is not included in FWH1707 ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2631
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby nageswaragunupudi » Thu Nov 22, 2018 9:21 am

Mr. Rick. Method drawimage was introduced in 18.01.
For 17.07, you may use oWnd:SayPalBmp(...)
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10264
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby Rick Lipkin » Thu Nov 22, 2018 2:33 pm

Rao

What am I doing wrong here with oWnd:SayPalBmp(...) . .I get just a blank grey background ?

Thanks
Rick Lipkin

Code: Select all  Expand view


nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)

DEFINE BITMAP oBMAP FILENAME (cDEFA+"\LOGO.BMP") of oWind        // logo
DEFINE BITMAP oBMP  FILENAME (cDEFA+"\FMLA.JPG") of oWind        // background

...
...
...

ACTIVATE WINDOW oWind                                         ;
   MAXIMIZED ;
   ON INIT  ( IF( nSCR1 < 1024, _ResMessage(nSCR1, nSCR2), ),_ChkOwner( oWind,cFirst)); // 560,230
   ON PAINT ( IF( xTEXT = "/NL", ,oWind:SayPalBmp( oBmp, 0,0, nSCR1, nSCR2 )),;   // background
                    PalBmpDraw( hDC, _UpDown(), _RightLeft(), oBMAP:hBitmap, oBMAP:hPalette,305,191 ));
   VALID ( IIF( !lExitPgm, _ExitPgm( .T.,@lExitPgm ) , .F. ))
 
User avatar
Rick Lipkin
 
Posts: 2631
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Using a Jpg instead of a Bitmap for Opening screen Graphics

Postby nageswaragunupudi » Thu Nov 22, 2018 3:34 pm

If you want to show background of a window, use brush instead.
Code: Select all  Expand view

DEFINE BRUSH oBrush FILE cDEFA+"\FMLA.JPG" RESIZE // or STRETCH
DEFINE WINDOW oWnd BRUSH oBrush
ACTIVATE WINDOW oWnd MAXIMIZED
RELEASE BRUSH oBrush
 


If you want to show any image centered (or at a particular place) on a window:
UPTO FWH17.12
Code: Select all  Expand view

DEFINE WINDOW oWnd
aBmp := oWnd:ReadPalBmpEx( cAnyImageFile )
ACTIVATE WINDOW oWnd ON PAINT oWnd:SayPalBmp( aBmp ) // aBmp or a valid hBitmap
PalBmpFree( aBmp )
 

From FWH18.01 we can use oWnd:ReadImage() and oWnd:DrawImage()

From FWH18.01, we can define BITMAP object with any image file, eg. bmp,png,jpg,etc., without the need for freeimage.dll
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10264
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 15 guests