Load BITMAP from .res File

New to FreeBASIC? Post your questions here.
Posts: 56
Joined: May 01, 2007 20:22

Load BITMAP from .res File

Postby Alexa » Jun 25, 2007 20:11


i want to Load a Bitmap file from the .res file

Bload "BITMAP_0", abc

i used it =) but this command can't read my BMP file from the .res =)

Thank you ...
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA

Postby KristopherWindsor » Jun 25, 2007 23:11

What is a .res file? The standard is .bmp, so you should just use that instead. If you took a .bmp file and renamed it to *.res, it won't work, because without the .bmp file extension, it thinks the file is "raw binary data" and not a standard bitmap.
Posts: 56
Joined: May 01, 2007 20:22

Postby Alexa » Jun 25, 2007 23:40

I think you don't know about a Resource File (*.rc , *.res)

Code: Select all


Dim As Ubyte Ptr buf2  = imagecreate(1,600)
Dim As HRSRC hResInfo
Dim As HGLOBAL hResData
Dim As Byte Ptr pData
Dim As Integer cbRes, i
hResInfo = FindResource( null, MAKEINTRESOURCE(1), RT_BITMAP )
cbRes = SizeofResource( null, hResInfo )
hResData = LoadResource( null, hResInfo )
pData = LockResource( hResData )
bload "[b]????[/b]" , buf


problem is loading a BMP file from a *.res file
Posts: 8024
Joined: May 28, 2005 3:28

Postby D.J.Peters » Jun 26, 2007 6:58

Hello Alexa
1) a bmp resource or a bmp as file has an other image header than ImageCreate produced an get and put needs.

2) BLOAD can only read from files not memory resource.

you need the bitmap in ImageCreate format


Code: Select all

Const bmpfile = "C:\WINDOWS\system32\setup.bmp"
screenres 800,600,32
Dim As Ubyte Ptr lpBMP=ImageCreate(800,600)
Bload bmpfile,lpBMP
Dim As Integer hFile=Freefile()
If Open("test.raw" For Binary Access Write As #hFile)<>0 Then
  Print "error: can't open raw file !"
end If
Put #hFile,,*lpBMP,32+800*600*4
Close #hFile
ImageDestroy lpBMP

now you need a way to include this raw file in your exe

Code: Select all

#ifndef __incany_bi__
#define __incany_bi__

#macro incany(strFile,lpAny)
  .section .text
  jmp .end_##lpAny
  .section .data
  .align 16
  .incbin ##strFile
  .section .text
  .align 16
  lea eax, .start_##lpAny
  mov dword Ptr [lpAny], eax
  End asm
#endif ' __incany_bi__

here an example how to use it

Code: Select all

#include "incany.bi"
Dim lpBMP As Any Ptr
screenres 800,600,32
Put (0,0),lpBMP,Pset
the bitmap in your exe has the same format as imagecreate would produce

(by the way *.rc *.res files works only on windows and "incany.bi" for both linux and windows)
Posts: 56
Joined: May 01, 2007 20:22

Postby Alexa » Jun 27, 2007 0:27

Thank you very much...

it was a good trick, i saw your replay too late, i had to use Thinstall and Embedded my Files with my Executable ...

also WinLicense and Themida are fully compatible with FB Compiled file ...

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 6 guests