Icon in Webview

Icon in Webview

Postby Natter » Sat May 27, 2023 6:37 pm

Hi,

Is it possible to show an icon in WebView not as a link to a file, but as a value (generate an icon from the source text) ?
For example
Code: Select all  Expand view
pol:=0
     hBmp:=BmpFromIcon(EXTRACTASSICON( 0, "Name.pdf", @pol))
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Icon in Webview

Postby Antonio Linares » Sun May 28, 2023 9:26 am

Dear Yuri,

Could you please describe what function EXTRACTASSICON( 0, "Name.pdf", @pol) would do ?
regards, saludos

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

Re: Icon in Webview

Postby Natter » Sun May 28, 2023 11:39 am

Code: Select all  Expand view
#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( EXTRACTASSICON )
{
  HICON hIcon;
  LONG hInstance = hb_parnl( 1 );
  char * lpIconPath = ( char * ) hb_parc( 2 );
  WORD lpiIcon = hb_parnl( 3 );

  hIcon = ExtractAssociatedIcon( ( HINSTANCE ) hInstance, lpIconPath, &lpiIcon );

  hb_stornl( lpiIcon, 3 );
  hb_retnl( ( LONG ) hIcon );
}

DLL32 FUNCTION ExtractAssociatedIcon( hIns AS LONG, cPth AS LPSTR, nInd AS LONG ) ;
AS LONG PASCAL FROM "ExtractAssociatedIconA" LIB "SHELL32.DLL"
 

Here it is described how to show an image in HTML not by link, but by value

https://www.w3docs.com/snippets/html/how-to-display-base64-images-in-html.html

To use this method I need to use hb_base64encode(), but I don't understand how to do it for
hBmp:=BmpFromIcon(EXTRACTASSICON( 0, "Name.pdf", @pol)) :(
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Icon in Webview

Postby Antonio Linares » Sun May 28, 2023 3:15 pm

Dear Yuri,

You may try this:

hDib = DibFromBitmap( hBmp )
DibWrite( cFileName, hDib )
hb_base64Encode( hb_memoRead( cFileName ) )
regards, saludos

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

Re: Icon in Webview

Postby nageswaragunupudi » Sun May 28, 2023 9:08 pm

While ExtractAssociatedIcon(...) is one way of fetching the icon of the associated application of a file, FWH provides much simpler way.

Most used FW_ReadImage()/oWnd:ReadImage() can also be used.

Just to check, please run this one line code:
Code: Select all  Expand view
XIMAGE( "name.pdf(256x256)" )


Image

FWH also allows us to select the size of the icon, vix. 16x16, 32x32, 64x64 or 256x256. Just add "(64x64") to the file name and use the function.

Next:
For base64 encoding of any image, FWH provides the class TImageBase64() (file fwh\source\classes\imageb64.prg)

Now let us see how to use.
In this sample, we will select 32x32 iconsize and prepare Base64 tag to be included in the html script directly.
We will also test a sample HTML

Code: Select all  Expand view
  // Read icon --> bmp --> png formatted string
   aBmp  := FW_ReadImage( nil, ".pdf(32x32)" )
   cPng  := GDIP_BMP2PNGSTR( aBmp[ 1 ] )
   PalBmpFree( aBmp )
   //
   
   // Use the class to prepare base64 tag
   oImage64 := TImageBase64():New( cPng )
   cTag := oImage64:MakeText( .f., .t., .f. )
   oImage64:TestHtml() // if you want to test before using the tag
 


cTag in the above program looks like this:
"<img src="data:image/png;base64,iVBORw0KGgoAAAANSU...../>"

You can insert this html Tag at the desired place in your HTML code.
To make sure this tag really works, you can test with:
Code: Select all  Expand view

oImage64:TestHtml()  
 


Image

Note:
If we want Icon of 16x16 or 32x32, we need not specify the full pdf file name. It is enough to specify ".pdf(32x32)"
If we want icon size 64x64 or 256x256, then we need to specify an existing file name in full.
Regards

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

Re: Icon in Webview

Postby Natter » Mon May 29, 2023 8:11 pm

Thank you very much, everything worked out !!! :D
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 95 guests