Icon as Bitmap
-
- Posts: 166
- Joined: May 14, 2007 12:20
- Location: Zagreb, Croatia
Icon as Bitmap
How can I load Icon (.ico file) as bitmap? Is it possible, and how?
Thanks!
Thanks!
Well, freebasic doesn't have a direct means to load ico files, but you can do it yourself once you know the file format.
www.wotsit.org
www.wotsit.org
One way would be to convert the icon to a bitmap and load the bitmap. This is a quick and dirty test app that uses GDI+ to do the conversion. It seems to work OK, but I tested it on only one icon.
Code: Select all
#include "win/gdiplus.bi"
'=====================================================================
using gdiplus
dim as GdiplusStartupInput gdipsi
dim as ULONG_PTR gdipToken
dim as GpImage ptr image
dim as wstring * 11 fnico = "fblogo.ico"
dim as wstring * 11 fnbmp = "fblogo.bmp"
dim as ImageCodecInfo ptr pImageCodecInfo
dim as UINT num, size
gdipsi.GdiplusVersion = 1
print GdiplusStartup( @gdipToken, @gdipsi, null )
print GdipLoadImageFromFile( @fnico, @image )
print GdipGetImageEncodersSize( @num, @size )
pImageCodecInfo = allocate( num )
print GdipGetImageEncoders( num, size, pImageCodecInfo )
for i as integer = 0 to num - 1
print *cast(wstring ptr,pImageCodecInfo[i].MimeType)
if *cast(wstring ptr,pImageCodecInfo[i].MimeType) = "image/bmp" then
print GdipSaveImageToFile( image, @fnbmp, _
@pImageCodecInfo[i].Clsid, null )
end if
next
print GdipDisposeImage( image )
GdiplusShutdown( gdipToken )
deallocate( pImageCodecInfo )
sleep
/'
enum Status
Ok = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
end enum
type ImageCodecInfo
Clsid as CLSID
FormatID as GUID
CodecName as WCHAR ptr
DllName as WCHAR ptr
FormatDescription as WCHAR ptr
FilenameExtension as WCHAR ptr
MimeType as WCHAR ptr
Flags as DWORD
Version as DWORD
SigCount as DWORD
SigSize as DWORD
SigPattern as BYTE ptr
SigMask as BYTE ptr
end type
GpStatus WINGDIPAPI GdipSaveImageToFile(
GpImage *image,
GDIPCONST WCHAR* filename,
GDIPCONST CLSID* clsidEncoder,
GDIPCONST EncoderParameters* encoderParams
);
'/
now I get a bunch of undeclared function errors
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0x9a): undefined reference to `GdiplusStartup@12'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0xb1): undefined reference to `GdipLoadImageFromFile@8'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0xc8): undefined reference to `GdipGetImageEncodersSize@8'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0xee): undefined reference to `GdipGetImageEncoders@12'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0x15d): undefined reference to `GdipSaveImageToFile@16'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0x17a): undefined reference to `GdipDisposeImage@4'
C:\Program Files\FreeBASIC\examples\ico to bmp.o:fake:(.text+0x18a): undefined reference to `GdiplusShutdown@4'
Sorry, I was assuming that the problem with the missing import library was just with my FB installation.
To build the import library I downloaded gdiplus.dll.def from here and ran this batch file:
For anyone who does not have GDIPLUS.DLL, it is available here. AFAIK the DLL is included with Windows XP and later.
BTW undefined <> undeclared
To build the import library I downloaded gdiplus.dll.def from here and ran this batch file:
Code: Select all
dlltool -k -d gdiplus.dll.def -l libgdiplus.dll.a
pause
BTW undefined <> undeclared
thanks MichaelW, the program compiles and runs but crashes at the end, here's the output.
the program exits without waiting.
when I press Return key to end the program windows reports an Aplication error:0
0
0
0
image/bmp
0
image/jpeg
image/gif
image/png
0
also if I add to the print statementsThe instruction "0x5ad776a3" referenced memory at "0xb96b3cdf". The memory could not be "read".
Click OK to terminate the program
Code: Select all
Print "1",GdiplusStartup( @gdipToken, @gdipsi, null )
Print "2",GdipLoadImageFromFile( @fnico, @image )
'etc
The size matches that of the import library that I built. I have now tested the 0.17 release version and the CVS from May 27, and the program works as it did before. Turning on DEP for all programs did not change the results. The program terminating without pausing on my XP system could possibly indicate a problem, but I get no error messages and the event logs show nothing related to the program. If you are using Windows 2000 or later, the event logs might provide some useful information.