FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour XIMage Compatibility with Image
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

XIMage Compatibility with Image

Posted: Sat Jan 06, 2018 09:51 PM

I'm trying to converte image with ximage but I have some problems

Wich is the comand lStretch into xImage ?
wich is the comand ScrollAdjust into ximage

I tried to zoo an ximage but not run

Local aItemsZoom:={"25%","50%","75%","100%","150%","200%"}

@ 230,295 COMBOBOX oCbxZoom VAR nZoom ITEMS aItemsZoom SIZE 60, 10 of oAllegati ;
on change (oImagePreview:nZoom(val(aItemsZoom[nZoom])/100) ,;
oImagePreview:refresh() ,;
Rinfresca_oDlgallegati() )

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: XIMage Compatibility with Image

Posted: Sat Jan 06, 2018 11:31 PM

The user does not need to help of combobox or any other means to zoom / unzoom ximage.
He can zoom or unzoom with mouse wheel ( or zoom and pinch gestures on a touch screen ). This gives much smoother zooming experience as well as the ability to choose the center (point of interest) of zooming.

Stretch is not provided intentionally because there is no point in viewing an image with distorted aspect. Ximage always keeps aspect ratio undisturbed.

Regards



G. N. Rao.

Hyderabad, India
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Sun Jan 07, 2018 08:50 PM
Rao,
After many problems I resolve some problems but I have two other problems, see the picture




I can show the icon of documents but the image is too big , I wish have a small image
I see black background why ?
then I not understood how run the zoom
i try with oImagePreview:nZoom(5) but not happen nothing
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 12:01 AM

May I know how are you reading the icon and how are you showing with ximage?

Regards



G. N. Rao.

Hyderabad, India
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 12:48 PM
for the size of Image I found the error I used the method setsize for xmage and Tpanel
now is good ( 200x200)

To read th eicon of document I use

Code (fw): Select all Collapse
  ico := ICON_EXEREAD( cFile, 4  )
 GDIBmpFromHIcon( ico, oImagePreview , oImagePreview:Super:nWidth(), oImagePreview:Super:nHeight() )

Function GDIBmpFromHIcon( hIcon , oImagePreview , nWidth, nHeight )
local ogbmp := GdiBmp():new()
ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:resize( nWidth,nHeight)
oImagePreview:SetSource(oGBmp:GetGDIHbitmap() )
oImagePreview:Refresh()
Return nil


probable GDIPLUSIMAGEFROMICO non run good

ximage is open normal as :

@ 0, 0 IMAGE oImagePreview SIZE oPanelPreview:nRight, oPanelPreview:nbottom OF oPanelPreview

oPanelPreview is a Tpanel and oPanelPreview:= oImagePreview
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 03:19 PM

Silvio , you resize icon to oPanelPreview:nRight, oPanelPreview:nbottom
in
ogbmp:resize( nWidth,nHeight)

and that is the result exactly what do you get...

Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 05:51 PM
Manuel,
I resolved for the size of Icon
the problem is I see black background arround the icon see the picture here:




then I wish Know if it is possible save the image files into different formats and wich, thanks

Can I disable mousewheel (zoom) it the document is not an image file but only an Icon of document ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 07:13 PM
Silvio .
Code (fw): Select all Collapse
ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:save( "icono.png")  // is posible png,jpg,bmp,tif 

oImagePreview:SetSource("icono.png" )
oImagePreview:Refresh()
ferase( "icono.png" ) 
ogbmb:end()
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 07:54 PM
This function not run

Code (fw): Select all Collapse
Function GDIBmpFromHIcon( hIcon , oImagePreview , nWidth, nHeight )
local ogbmp := GdiBmp():new()
ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:save( "icono.png")  // is posible png,jpg,bmp,tif
oImagePreview:SetSource("icono.png" )
ogbmp:resize( nWidth,nHeight)
oImagePreview:Refresh()
ferase( "icono.png" ) 
ogbmp:end()
Return ni


first error
Code (fw): Select all Collapse
Application
===========
   Path and name: C:\Work\Prg\test_allegati\Allegati.Exe (32 bits)
   Size: 3,786,752 bytes
   Compiler version: Harbour 3.2.0dev (r1703231115)
   FiveWin  version: FWH 17.12
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200 

   Time from start: 0 hours 0 mins 3 secs 
   Error occurred at: 01/08/18, 20:50:53
   Error description: Error BASE/1004  Message not found: GDIBMP:END
   Args:
     [   1] = O   GDIBMP

Stack Calls
===========
   Called from:  => __ERRRT_SBASE( 0 )
   Called from: ../../../tobject.prg => GDIBMP:ERROR( 0 )
   Called from: ../../../tobject.prg => (b)HBOBJECT( 0 )
   Called from: ../../../tobject.prg => GDIBMP:MSGNOTFOUND( 0 )
   Called from: ../../../tobject.prg => GDIBMP:END( 0 )
   Called from: Source\test.prg => GDIBMPFROMHICON( 649 )
   Called from: Source\test.prg => INSERISCIALLEGATI( 241 )
   Called from: Source\test.prg => (b)ALLEGATI( 180 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:INITIATE( 714 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 906 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 296 )
   Called from: Source\test.prg => ALLEGATI( 180 )
   Called from: Source\test.prg => TEST( 56 )


if I rem the line ogbmp:end()

I not see any image




If the function is this
Code (fw): Select all Collapse
Function GDIBmpFromHIcon( hIcon , oImagePreview , nWidth, nHeight )
Local hBmp
local ogbmp := GdiBmp():new()
ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:resize( nWidth,nHeight)

                       if oImagePreview:cargo == NIL
                          oImagePreview:cargo =  oImagePreview:GetHBitmap()
                       else
                          DeleteObject( oImagePreview:GetHBitmap() )
                       endif

 hBmp := oGBmp:GetGDIHbitmap()

oImagePreview:SetSource( hBmp )

oImagePreview:Refresh()

Return nil


I see the icon on oImagePreview but with black background

I saw there is this function GDIP_NEWALPHABMP How I can use it to erase black background ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 09:31 PM
this is good for me ...
Code (fw): Select all Collapse
#include "fivewin.ch"

//----------------------------------------------------------------------------//

function Main()

   local aImages, oWnd, oFont, oBrush, oBrw, oImage

   FW_SetUnicode( .t. )
   HB_SETCODEPAGE( "UTF8" ) // Harbour (not xHarbour) to display unicode filenames

   aImages  := ReadFolder()

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   DEFINE BRUSH oBrush FILE "..\bitmaps\backgrnd\stone.bmp"
   DEFINE WINDOW oWnd
   oWnd:SetFont( oFont )

   msginfo( len( aImages ) )
 
   DEFINE BUTTONBAR oWnd:oBar SIZE 100,32 2007
   SET MESSAGE OF oWnd TO "" 2007

   DEFINE BUTTON OF oWnd:oBar PROMPT "Center"     CENTER ACTION ( oImage:Center(),    oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Fit Width"  CENTER ACTION ( oImage:FitWidth(),  oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Fit Height" CENTER ACTION ( oImage:FitHeight(), oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Fit Rect"   CENTER ACTION ( oImage:FitRect(),   oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Rotate"     CENTER ACTION ( oImage:Rotate(),    oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Zoom"       CENTER ACTION ( MsgInfo( "Zoom/Unzoom with Mouse Wheel" ),  oImage:SetFocus() )
   DEFINE BUTTON OF oWnd:oBar PROMPT "Pan/Move"   CENTER ACTION ( MsgInfo( "Drag with Mouse" ),  oImage:SetFocus() )


   @ oWnd:oBar:nHeight,0 XBROWSE oBrw SIZE 300,-oWnd:oMsgBar:nHeight ;
      PIXEL OF oWnd DATASOURCE aImages COLUMNS 1 ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nStretchCol   := 1
      :bChange       := { || carga( oBrw:aRow[ 2 ],oImage ) }
      //
      :CreateFromCode()
   END

   @ oWnd:oBar:nHeight,300 XIMAGE oImage SIZE 0,-oWnd:oMsgBar:nHeight ;
      OF oWnd SOURCE ""   //MEMOREAD( oBrw:aRow[ 2 ] )

   oImage:SetBrush( oBrush )

   WITH OBJECT oWnd
      :nWidth     := ScreenWidth()  * 0.6
      :nHeight    := ScreenHeight() * 0.6
   END

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont
   RELEASE BRUSH oBrush


return nil

//----------------------------------------------------------------------------//

static function ReadFolder

   local aImages  := {}
      local c, cPath, aDir

  
      cPath    := ".\" 
      aDir     := Directory( cPath + "*.*" )
      AEval( aDir, { |a| If( a[ 2 ] > 32000, AAdd( aImages, { a[ 1 ], TrueName( cPath + a[ 1 ] ) } ), nil ) } )
   

   ASort( aImages,,,{ |x,y| Lower( x[ 1 ] ) < Lower( y[ 1 ] ) } )

return aImages

//----------------------------------------------------------------------------//

static function carga( cFile , oImage )
local hicon := ICON_EXEREAD( cFile, 4  )
local ogbmp := GdiBmp():new()

ogbmp:= GDIPLUSIMAGEFROMICO( hicon )

oimage:SetSource( ogBmp:GetGDIHbitmap() )
oImage:Refresh() 
ogbmp:end()

Return nil
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 09:51 PM
other approach is ---

Code (fw): Select all Collapse
static function carga( cFile , oImage )
local hicon := ICON_EXEREAD( cFile, 4  )
local ogbmp := GdiBmp():new()

ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:save( "icono.png")
oimage:SetSource( memoread( "icono.png" ) )
oImage:Refresh() 
ferase("icono.png" ) 
ogbmp:end()

Return nil
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Mon Jan 08, 2018 10:15 PM
I compiled your test

I change only the path cPath := ".\Doc\"

where I put these files to try the test



But when I run the exe I see only six files



then I try t select one for a sample tga file



or another for sample the pdf file




Probable there is something not run ok , isn'it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM

Re: XIMage Compatibility with Image

Posted: Tue Jan 09, 2018 08:12 AM
Yes. Silvio .

HB_FUNC( GDIPLUSIMAGEFROMICO ) from fwh has a bug, in my gdiplus.cpp version is corrected.
I have reported it to Cristobal for correction.

The code propose by nages is more good solution : :-)

Code (fw): Select all Collapse
static function carga( cFile , oImage )

local hicon := ICON_EXEREAD( cFile, 4  )
local   hBmp  := HBMPFROMHICON( hIcon )
   DestroyIcon( hIcon )
   oImage:SetSource( hBmp )
   DeleteObject( hBmp )

Return nil
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: XIMage Compatibility with Image

Posted: Tue Jan 09, 2018 08:24 AM
yes Rao Function Run Good




GDIPLUSIMAGEFROMICO in gdiplus have bug

I have 3 different function

1. the yours ( here not pubblish)

2. the version on fwh12 ( where I see nothing)

Code (fw): Select all Collapse
HB_FUNC( GDIPLUSIMAGEFROMICO )
{
 HICON hIcon = ( HICON ) fw_parH( 1 ) ;

 ICONINFO ii ;
 GetIconInfo(hIcon, &ii);
 BITMAP bmp;
 //GetObject(ii.hbmColor, sizeof(bmp), &bmp);
 //GetObject(ii.hbmMask, sizeof(bmp), &bmp);

 //Bitmap * temp = new Bitmap(ii.hbmColor, NULL);
 Bitmap * temp = new Bitmap(ii.hbmMask, NULL);

 DeleteObject(ii.hbmColor);
 DeleteObject(ii.hbmMask);

 Bitmap* newImage =  BitmapFromAlphaBmp( temp ) ;

 hb_retptr( newImage );

}



3 . an oldest release where I see the icon with black background
Code (fw): Select all Collapse
HB_FUNC( GDIPLUSIMAGEFROMICO )
{
   HICON hIcon = ( HICON ) fw_parH( 1 ) ;

   Bitmap * newImage =  new Bitmap( hIcon );
   hb_retptr( newImage );
}
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion