ico := nImage
hBmp := BmpFromIcon( ico )
DeleteObject( oImage:hBitmap )
oImage:hBitmap = hBmp
oImage:HasAlpha()
oImage:Refresh()
DestroyIcon( ico )
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
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
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 ) ;
}
#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
}
#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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 56 guests