Author |
Topic: Load Bitmap from RGB triplet data... (Read 725 times) |
|
James
New Member
member is offline
Posts: 42
|
|
Load Bitmap from RGB triplet data...
« Thread started on: Feb 4th, 2012, 10:15am » |
|
What would be interesting is if you could load a bitmap from RGB triplet data like this:
Code:open "pictures.res" for input as #datafile
Loadbmp "smiley", 320, 240, #datafile, 3
#screen.box, "drawbmp smiley 0 0"
In this case you would basically be loading 320 X 240 X 3 byte slots, slot number 3
or
Code:Loadbmp "face", 640, 480, #differentfile, 100
Load bitmap face, size 640 by 480, from #differentfile, slot number 100
Total bytes loaded this time: 921600
It would be interesting to be able to do loadbmp from raw data. 8-)
----------
John 3:3 Jesus answered and said unto him, Verily, verily, I say unto thee, Except a man be born again, he cannot see the kingdom of God.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Load Bitmap from RGB triplet data...
« Reply #1 on: Feb 4th, 2012, 12:45pm » |
|
on Feb 4th, 2012, 10:15am, James wrote:What would be interesting is if you could load a bitmap from RGB triplet data |
|
Right, this time I really have been able to write code which does it:
Code: nomainwin
WindowWidth = 320
WindowHeight = 240
open "Load raw RGB data" for graphics_nsb as #screen
#screen "trapclose [quit]"
call loadrgb "smiley", 320, 240, "C:\smiley.rgb", 0
#screen "drawbmp smiley 0 0"
wait
[quit]
close #screen
end
sub loadrgb bmp$, width, height, file$, slot
struct bmi, size as ulong, width as long, height as long, _
planes as short, bitcount as short, compression as ulong, _
sizeimage as ulong, xpermeter as long, ypermeter as long, _
clrused as ulong, clrimportant as ulong
struct dib, bits as long
bmi.size.struct = len(bmi.struct)
bmi.width.struct = width
bmi.height.struct = height
bmi.planes.struct = 1
bmi.bitcount.struct = 24
calldll #gdi32, "CreateDIBSection", 0 as long, bmi as struct, _
0 as long, dib as struct, 0 as long, 0 as long, hdib as long
open file$ for binary as #rgbfile
seek #rgbfile, slot * width * height * 3
hfile = hwnd(#rgbfile)
buffer = dib.bits.struct
size = width * height * 3
calldll #kernel32, "ReadFile", hfile as long, buffer as long, _
size as long, dib as struct, 0 as long, ret as long
close #rgbfile
loadbmp bmp$, hdib
calldll #gdi32, "DeleteObject", hdib as long, ret as long
end sub This nearly works in LB4, except that it relies on the LBB extension of HWND() working with file handles as well as window handles.
Richard.
|
|
Logged
|
|
|
|
James
New Member
member is offline
Posts: 42
|
|
Re: Load Bitmap from RGB triplet data...
« Reply #2 on: Feb 4th, 2012, 2:01pm » |
|
Thanks, Richard, that's nice! I tried it out!
What is the code's license? I hope it's public domain...
--------
Romans 6:23 For the wages of sin is death; but the gift of God is eternal life through Jesus Christ our Lord.
|
« Last Edit: Feb 4th, 2012, 2:05pm by James » |
Logged
|
|
|
|
|