bmpfromico

bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 3:06 pm

CAn I load a temporary Bmp from an Ico and show it on Image Control ?
If Yesy, how ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby Antonio Linares » Fri Jul 03, 2015 3:28 pm

I just sent an email to Manuel Alvarez as he is a master with GDI+ and surely it may help for what you want to do.

Lets wait for his answer
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 3:44 pm

Sorry Antonio,

I have on Listview many items

when I add a item I made

nImage := Icon_Read(cNewfile)
ILADDICON( oImageListSmall:hImageList, nImage )
nImage := max(0,ILADDICON( oImageListBig:hImageList, nImage ) )
DestroyIcon(nImage)
oItem = TListViewItem():New( oList )
oItem:cText = cNewfile
oItem:nImage = nImage
oItem:Create()



we have the icon ... of a file

then I saw there is a function Made from Daniel

HB_FUNC( BMPFROMICON )
{
HICON hIcon = ( HICON ) hb_parnl( 1 );
HDC HDCMem = GetDC( GetDesktopWindow() );
HDC hDC = CreateCompatibleDC( HDCMem );
HBITMAP hBitmap = CreateCompatibleBitmap(HDCMem, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hDC, hBitmap);
DrawIcon(hDC, 0, 0, hIcon);
SelectObject(hDC, hOldBitmap);
DeleteDC(hDC);

hb_retnl( ( LONG ) hBitmap );
}




then I thinked

ico := nImage
hBmp := BmpFromIcon( ico )


now How I can make to show hBmp into Image control ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby Antonio Linares » Fri Jul 03, 2015 4:22 pm

DeleteObject( oImage:hBitmap )
oImage:hBitmap = hBmp
oImage:Refresh()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41206
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 4:42 pm

it run BUT bad

look please ( I dropped a PPTX file )

Image

Any solution ?
perhpas we can create the bitmap trasparent no black background ...perhaps...
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby mastintin » Fri Jul 03, 2015 4:47 pm

Silvio ,
BmpfromIco function is include en fwh .

Code: Select all  Expand view


ico := nImage
hBmp := BmpFromIcon( ico )
DeleteObject( oImage:hBitmap )
oImage:hBitmap = hBmp
oImage:HasAlpha()
oImage:Refresh()
DestroyIcon( ico )

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 4:58 pm

thanks
can I make a big bmp ?

change this line ?
HBITMAP hBitmap = CreateCompatibleBitmap(HDCMem, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));

Itried to make

HBITMAP hBitmap = CreateCompatibleBitmap(HDCMem, 128, 128);

the bitmap is large but the icon is small

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby mastintin » Fri Jul 03, 2015 5:17 pm

for resize bmp , i use gdiplus....

Function GDIBmpFromIco( cFileIcon , oImage )
local ogbmp := GdiBmp():new( cFileIcon)
ogbmp:resize( nWidth,nHeight)
DeleteObject( oImage:hBitmap )
oImage:hBitmap := oGBmp:GetGDIHbitmap()
oImage:HasAlpha()
oImage:Refresh()
ogbmp:end()
Return nil
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 5:47 pm

Obj\urllink.c:
[1]:PORC.EXE C:\Work\Prg\Allegati\Resource\default.rc /I c:\work\pellesc\include /I win
[1]:iLink32.Exe -Gn -aa -Tpe -s @Allegati.bcl
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_HB_FUN_HB_NUMTOHEX' referenced from C:\WORK\FWH\LIB\FIVEHX.LIB|TGDIPLUS
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby mastintin » Fri Jul 03, 2015 6:06 pm

silvio add this function to prg ...

Code: Select all  Expand view



Function lIsPng( cStr )
local cIsPng :=  left( cStr, 8 )
local lPng
local i, nChar, cChar
local cHex:= ""

 For i = 1 To 8
   nChar = Asc( SubStr( cIsPng , i, 1 ) )
    //cChar = hb_NumToHex( nChar )  // for harbour
    cChar = NumToHex( nChar )   // for xHarbour
    cChar:= If( Len( cChar ) == 1, "0", "" ) + cChar
    cHex:= cHex + Upper( cChar )
  Next

  lPng := ( cHex == "89504E470D0A1A0A" )
Return lPng

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: bmpfromico

Postby Silvio.Falconi » Fri Jul 03, 2015 6:52 pm

Manuel,
I modify the tgdiplus class
now it is compiled

but perhaps there is something not run also
cFile cab be for a sample : test.pptx

ico := ICON_EXEREAD(cfile)
GDIBmpFromIco( ico, oImagePreview )

give me a message fichero no encontrado



HB_FUNC( ICON_EXEREAD )
{
SHFILEINFO sfi;

ZeroMemory(&sfi, sizeof(SHFILEINFO));

SHGetFileInfo(hb_parc(1), 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON );

hb_retnl( ( LONG ) sfi.hIcon );

}
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby mastintin » Sat Jul 04, 2015 7:21 am

ok Silvio , back to top :-)
This code is ok for me :

Code: Select all  Expand view

Function Main ()
local ownd
local oimage

 DEFINE WINDOW oWnd TITLE "Testing hicon to bmp " FROM 5,5 TO 400, 600 PIXEL ;
 COLOR CLR_GRAY, CLR_GRAY
   
    @ 20,2 button "crear" size 40,20 pixel Action imagenfromico( oimage )
    @ 20 ,130 Button "salir" Action ownd:end() size 40,20 pixel
     
   @ 3, 38 BITMAP oimage FILE "" size 148,148 of oWnd

   ACTIVATE WINDOW oWnd

Return (nil)


Function imagenfromico( oImage )
local cFile:= cGetfile("coge","*.*")
local ico := ICON_EXEREAD( cFile  )
        BmpFromHIcon( ico, oImage , oImage:Super:nWidth(), oImage:Super:nHeight() )
        DestroyIcon( ico )
Return nil


Function BmpFromHIcon( hIcon , oImage , nWidth, nHeight )
local hBmp := BmpFromIcon( hIcon )
       DeleteObject( oImage:hBitmap )
       oImage:hBitmap = resizebmp( hBmp, nWidth, nHeight )
       DeleteObject( hBmp )
      oImage:HasAlpha()
      oImage:Refresh() 
Return nil

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: bmpfromico

Postby nageswaragunupudi » Sun Jul 05, 2015 2:59 am

Just for information.
We need not have a separate new function ICON_EXEREAD. There is already FWH function ICON_READ( <cfile> ) for the same purpose. The functions already in FWH are adequate for this purpose.
Regards

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

Re: bmpfromico

Postby Silvio.Falconi » Sun Jul 05, 2015 12:53 pm

Mr Nages I found that function on this forum from Daniel Garcia Gill

Manuel ( Mastintin) I saw the best resolution is 64X64 because if I make the image with the size of Image control is too Big
Please see here :

version with Image file and contexmenu of file
Image

Version with a pdf file dropped into

Image

I wish send thanks to all my friends
thanks to Antonio Linares and AntoninoP for modifies to Listview class
thanks to AntoninoP for file contexmenu and other functions (I hope he found a solution to show the lPreviewHeader also on Bcc585)
thanks to Manuel Mastintn for support Tgdiplus class
thanks to Emg for the tech support
thanks to Paco for the c5Tstatusbar and TpanelEx classes
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6716
Joined: Thu Oct 18, 2012 7:17 pm

Re: bmpfromico

Postby mastintin » Tue Jul 07, 2015 10:21 pm

Silvio , Good news :-)
New code for Icons ...
Change this function in gdiplus.cpp ...

Code: Select all  Expand view



HB_FUNC( GDIPLUSIMAGEFROMICO )
{
  HICON hIcon = ( HICON ) hb_parnl( 1 ) ;

 ICONINFO ii ;
 GetIconInfo(hIcon, &ii);
 BITMAP bmp;
 GetObject(ii.hbmColor, sizeof(bmp), &bmp);
 
 Bitmap * temp = new Bitmap(ii.hbmColor, NULL);

 BitmapData bmpData;
 
 int nWidth  = temp->GetWidth()  ;
 int nHeight = temp->GetHeight() ;
 
 Rect rect(0, 0, nWidth, nHeight);
 
 temp->LockBits(&rect, ImageLockModeRead, temp->GetPixelFormat(), &bmpData );
 
 byte* imgPtr = (byte*)(bmpData.Scan0) ;
 int bheight = bmpData.Height;
 int bwidth = bmpData.Width;
 int bstride = bmpData.Stride;

 Bitmap *original = new Bitmap( bwidth, bheight, bstride, PixelFormat32bppARGB, imgPtr );
 temp->UnlockBits( &bmpData ) ;

 Bitmap* newImage  = new Bitmap( nWidth, nHeight, PixelFormat32bppARGB ) ; // original->GetPixelFormat() );

 Graphics * graphics = new Graphics( newImage );
 graphics->DrawImage( original ,0, 0, nWidth, nHeight);

 delete temp ;
 delete original ;
 
 hb_retnl( ( HB_LONG ) newImage ) ;
           
}

 


Add this code ad end of gdiplius.cpp ... ( is c++ code )
ICON_EXEREAD function has 2 parameters name file , and Size ..
0->LARGE 32x32
1->SMALL 16x16
2->48x48
3-> These images are the size specified by GetSystemMetrics called with SM_CXSMICON and GetSystemMetrics called with SM_CYSMICON.
4-> Windows Vista and later. The image is normally 256x256 pixels.

Code: Select all  Expand view


#include <commctrl.h>
#include <commoncontrols.h>

HB_FUNC( ICON_EXEREAD )
{
   
HICON hico ;  
SHFILEINFO sfi = { 0 };

 LPCTSTR pName = ( LPCTSTR ) hb_parc( 1 ) ;
 
 SHGetFileInfo(  pName , -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX  );
 
 HIMAGELIST* imageList;
 
 HRESULT hResult = SHGetImageList( hb_parni( 2 ) , IID_IImageList2, (void**)&imageList );

 if(hResult == S_OK) {
   
   ((IImageList*)imageList)->GetIcon(sfi.iIcon,ILD_NORMAL|ILD_TRANSPARENT , &hico);
  }
 
   #ifndef _WIN64
      hb_retnl( ( LONG )  hico );
   #else  
      hb_retnll( ( LONGLONG ) hico );
   #endif
 
}

 


And test ...
Code: Select all  Expand view



#include "FiveWin.ch"

Function Main ()
local ownd
local oimage

 DEFINE WINDOW oWnd TITLE "Testing GDI+ Class" FROM 5,5 TO 400, 600 PIXEL
   
    @ 20,2 button "crear" size 40,20 pixel Action imagenfromico(oimage )
   
    @ 20 ,130 Button "salir" Action ownd:end() size 40,20 pixel
     
   @ 3, 38 BITMAP oimage FILE "" size 220,220 of oWnd

   ACTIVATE WINDOW oWnd


Return (nil)


Function imagenfromico(oImage )
local cFile:= cGetfile("coge","*.*")
local ico := ICON_EXEREAD( cFile, 4  ) // for ico, dll and exe files
GDIBmpFromHIcon( ico, oImage , oImage:Super:nWidth(), oImage:Super:nHeight() )

Return nil


Function GDIBmpFromHIcon( hIcon , oImage , nWidth, nHeight )
local ogbmp := GdiBmp():new()
ogbmp:hBmp:= GDIPLUSIMAGEFROMICO( hicon )
ogbmp:resize( nWidth,nHeight)
DeleteObject( oImage:hBitmap )
oImage:hBitmap := oGBmp:GetGDIHbitmap()
oImage:HasAlpha()
oImage:Refresh()
ogbmp:end()

Return nil

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 11 guests