converting pictures to icon in blitz

Community Forums/Showcase/converting pictures to icon in blitz

ford escort(Posted 2003) [#1]
here the code to convert a picture in an icon for your blitz programs :) i still have the biggest part to do, including the icon in the exe... if someone know how to add a ressource in an exe i'm interested by the doc to implement this in blitz
Graphics 800,600,32,2
bmp$="image1.bmp"
filename$="icon.ico"
Global offset=0
Global icon
saveicon(bmp$,filename$)
Function saveicon(bmp$,filename$)
	buffer=LoadImage(bmp$)
	icon=CreateBank(100000)
	If buffer
		;-------------------------------ICONDIR structure
		poke(0,1)						;reserved must be 0 					(WORD)0
		poke(1,1)						;ressource type icon=1					(WORD)2
		poke(1,1)						;how many images 1						(WORD)4
		;-------------------------------ICONDIR ENTRY
		poke(ImageWidth(buffer),0)      ;width in pixel of the picture			(BYTE)6
		poke(ImageHeight(buffer),0)		;height in pixel of the picture			(BYTE)7
		poke(0,0)						;#color in image 0 if >8bpp 			(BYTE)8
		poke(0,0)						;reserved must be 0 					(BYTE)9
		poke(1,1)						;color planes 							(WORD)10
		poke(32,1)						;bit per pixel							(WORD)12
		bytecount=((ImageWidth(buffer)*ImageHeight(buffer))*4);x,y*4 bytes
		poke(bytecount+40+(ImageWidth(buffer)*ImageHeight(buffer))/8,2)	;how many bytes in this ressource		(DWORD)14
		poke(offset+4,2)				;where in the file is the bitmap data	(DWORD)18
		;--------------------------------DIB header
		poke(40,2)						;lenght of the header					(DWORD)22
		poke(ImageWidth(buffer),2)		;width in pixel of the picture			(DWORD)26
		poke(ImageHeight(buffer)*2,2)		;width in pixel of the picture		(DWORD)30
		poke(1,1)						;color planes 1 in most case			(WORD)34
		poke(32,1)						;bit per pixel							(WORD)36
		poke(0,2)						;compression value						(DWORD)38
		poke(bytecount,2)				;pixeldata size							(DWORD)42
		poke(0,2)						;ppm									(DWORD)46
		poke(0,2)						;ppm									(DWORD)50
		poke(0,2)						;number of color 0=max                  (DWORD)54
		poke(0,2)						;number of color indice importants 0=max(DWORD)58
		SetBuffer ImageBuffer(buffer)
	For y=ImageHeight(buffer)-1 To 0 Step-1
		For x=0To ImageWidth(buffer)-1;To  Step-1
			GetColor x,y
			poke(ColorBlue(),0)
			poke(ColorGreen(),0)
			poke(ColorRed(),0)
			poke(255,0)
		Next 
	Next
	For a=1 To bytecount/8
		poke(0,0)
	Next
	
	EndIf
fil=WriteFile(filename$)
WriteBytes(icon,fil,0,offset)
CloseFile fil
End Function
Function poke(value,typ)
Select typ
	Case 0;byte
		PokeByte icon,offset,value:offset=offset+1
	Case 1;word
		PokeShort icon,offset,value:offset=offset+2
	Case 2;long
		PokeInt icon,offset,value:offset=offset+4
End Select
End Function




ckob(Posted 2003) [#2]
I heard a hex editor was a easy way of editing the icon in the exe


soja(Posted 2003) [#3]
surely not a hex editor...? more likely a resource editor...


ford escort(Posted 2003) [#4]
yes, i know that but what i wan't to do is to add an icon to a blitz executable with a blitz function so i have to learn how to make a ressource editor.
anyone have tips ?


Neo Genesis10(Posted 2003) [#5]
Ford: Can the icon be directly imported to Blitz proggies? I ask because I designed an icon file using C++ which failed. My mistake? Having a 16 color icon. Rectifying my mistake it still failed. This time the icon had 2 versions in the same file - 16 color and 256. Just a thought which I would share.


Litobyte(Posted 2003) [#6]
To replace blitz exe icon you should use only a 256 color icon in your .ico file.

In that case you can replace the icon in blitz exe

Interesting code!!!!
I was looking for it!

I was tired to install and use 30 days evaluation stuff to create icon :)

Now I can do them in gimp then save them as icon thanks to your code.

Masta mr ford escort :)


ford escort(Posted 2003) [#7]
I WOULD LIKE to include such a function to add an icon to a blitz or whatever else)executable unfortunaly i have no information on how and where are stored the icons in the exe himself, and with the last incarnation of blitzplus, there is no more icon in the executable so i can't use a simple search and replace icon function...

if someone have info about the rsc stuff in exe i'll be happy to have a look at the problem!


jfk EO-11110(Posted 2003) [#8]
Thanks a lot, that's very useful! Does this Source support
multiple Icon Formats? I mean, in most Icons there are 3
Icons stored, 16*16, 32*32 and 48*48 Pixels if remember
right.


Litobyte(Posted 2003) [#9]
If it would, it would'nt be good for blitz I'm afraid :(

Anytime I tried to replace a multiple format icon file to blitz's exe I couldn't, so I think a plain 8bit 256 color would be great (if we plan to use it only to replace blitz's exe icons)

What icon format does this code exports ? (haven't tried it yet)


jfk EO-11110(Posted 2003) [#10]
Zurk - surprisingly i think i remember I replaced a 3-Format Icon in a Blitz Exe using the Resouce Hacker. Tho I'm not absolutely shure anymore.


skidracer(Posted 2003) [#11]
ford, the following should let you download the .exe file spec, interested in helping if you need any:

http://www.microsoft.com/whdc/hwdev/download/hardware/pecoff.pdf


ford escort(Posted 2003) [#12]
@jfk, not tested but it should work it's the oficial icon format, but you have to modify a bit the code, (WORD 4) is the number of icons in the file then you have to enter for each icon the icondir entry, be carreful with the (DWORD 18) also in each icondir entry :o) for the bitmap position in the icon file.
@skidracer i'll look at it but i had searched previously info about that.it look that the ressource code have to be decompiled/compiled i looked at ressource hacker sites and i have the feeling that making a compiler/decompiler for ressource can be a too big task for me for some reasons like time consuming :) but i'll check your file anyway :)


Litobyte(Posted 2003) [#13]
Ok, but, at the moment:

what are the feature of the above code ?

It saves a bitmap into a 256 8bit 32x32 icon ? or what else?

thanx


ford escort(Posted 2003) [#14]
it save a picture in ico format, try it you'll see :) i have included an icon made with this code in a blitz exe with ressource hacker and that worked for me...


Litobyte(Posted 2003) [#15]
Ok, fine :)
thanks

any link for a free /(not expiring) res editor ?


ford escort(Posted 2003) [#16]
sure :)
http://www.users.on.net/johnson/resourcehacker/


jfk EO-11110(Posted 2003) [#17]
all freeware to the people! :)


Litobyte(Posted 2003) [#18]
cheers mate :)