Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 storing bitmaps in memory

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
Vankwysha Posted - May 04 2005 : 06:53:51 AM
hey again,

i'm using vb.net, directdraw and directx9 still, and i'm wondering if there is any way to keep a bitmap in memory before you load it as a sprite to go on a backbuffer. The subprogram to load the sprite takes a filename as an argument, but i do not wish to load my bitmaps from file. I am using an encrypted image format that i designed to stop users tampering with the game images, and as such my game has to decrypt the images on start-up. I was considering making temporary image files while the game was running, but i think that this would be tacky and slow.

is there any way for me to save my decrypted bitmaps in a class or variable and then load them as sprites?

thanks in advance.
15   L A T E S T    R E P L I E S    (Newest First)
Vankwysha Posted - May 14 2005 : 07:45:22 AM
I haven't had time over the last few days to fully implement my solution, but I have got the basics working.

Basically, I've simply removed the compression from the file format (as it overly complicates things) and simply have each of the bitmaps one after the other in a single file. One of my friend designed a DLL which contains the necessary classes and functions for packing and unpacking bitmaps into a single file, and once I fully understand this I'll be happy to share the full solution.

However, once the images have been unpacked, I simply store them in byte arrays and then load them into memory stream objects.

Again, thanks all round.
Eric Coleman Posted - May 11 2005 : 10:15:34 AM
Any tips or suggestions for the rest of us on how you did it?
Vankwysha Posted - May 11 2005 : 04:40:52 AM
Well, I've finally figured it out. It's taken a while, but I've now got my bitmaps decrypted successfully and loaded as sprites. I'd just like to thank all of you for your time and help.
Eric Coleman Posted - May 10 2005 : 12:25:16 PM
Well, I don't know anything about your image format, but you need to convert it to a byte array. Then simply use this code to create your stream.
  
Dim Data() As Byte
ReDim Data(10)  
Dim S As System.IO.MemoryStream  
S = New System.IO.MemoryStream(Data)  
  

Vankwysha Posted - May 10 2005 : 04:24:52 AM
So far, I've been able to compress and decompress my images, and I know how to load a bitmap or stream object into the draw sub, however, I haven't worked out how to make the link between. Once I decompress the data, it just sits in a binary variable. How do I then load that variable into a stream (or bitmap)?
Eric Coleman Posted - May 09 2005 : 10:51:06 PM
The fact that you can load data from a "stream" or "bitmap" ojbect seems to have been ignored in this thread. The "stream" object allows you to load graphical data from memory, which is what you're asking about. The trick is to make sure that the data in your stream is uncompressed, which is what you have to do regardless of how you store or use the data.

Are you having trouble reading data from a file or are you having trouble uncompressing the data or what? The concept of what you need to do is simple, Disk -> Uncompress -> Memory -> CreateSurfaceFromMemory. Lachlan already told you how to do that last part, use system.IO.Stream.
Vankwysha Posted - May 08 2005 : 3:55:26 PM
Well, I didn't have it working in VB6 to start with, since then I've made some major revisions to the design of the game that just wouldn't work with VB6, and also because I no longer own VB6.
2dcoder Posted - May 08 2005 : 04:12:23 AM
hmm, curious... since it sounds like you already have it working in vb6, what benefits do you see going to VB.Net? Better performance, better compatbility for end users ? ?
Vankwysha Posted - May 07 2005 : 7:36:31 PM
The function can take a FileStream or a System.Drawing.Bitmap object, so eventually I will load my bitmap into one of those, but for now I'll just concentrate on converting the rest of my game from VB6 to VB.NET.
Crysstaafur Posted - May 07 2005 : 06:54:34 AM
One quick question Van, the 'variable' that you are trying to stash your image into, is it
an actual variable, a label for an object, an indexed array, or a pointer address?

Also if the function you are trying to call is asking for a filename, the only two ways I know of
feeding it info break down to simple and hard as hell...

if you've settled the file issue then ignore the rest of this post... :)

simple:feed a file into the function.(the state of the file doesn't matter as long as it matches what it expected when said function is called...)

complex:(sighs) try finding out what memory address or object the function is attempting to load the image into, then simply pop the information into that. This undoubtedly would require some skill with win32 asm or an uncanny grasp of memory manipulation.. either way.. the issue of learning the internals of the functions binary is an issue.. I am still not 100% on whether that would even work...

2dCoder: 'So long and thanks for all the fish...' lol
Vankwysha Posted - May 07 2005 : 04:13:53 AM
Hmmm, I spose that is a good point. Maybe I'll worry about this stuff once I'm done.
2dcoder Posted - May 06 2005 : 11:30:50 PM
"However, I have managed to create my decryption function ..."
"However, I get a System.OutOfMemory exception..."

Doesn't look like you have it working yet. ;) Is your game already done by the way? Usually this kind of stuff is coded after the game is done. Going to give us a peek? :)
Vankwysha Posted - May 06 2005 : 6:24:21 PM
Yeah, I'm starting to look that way too. However, I have managed to create my decryption function that should load the bitmap into a temporary varirable. However, I get a System.OutOfMemory exception. I can't understand why, the image is only about 10 KB.
2dcoder Posted - May 06 2005 : 08:25:21 AM
jeesh.... sometimes we code to impress ourselves more than the user playing our game. :) I've also used the extension renaming. It works and is usually enough to keep people from looking at your graphics from Explorer.
Crysstaafur Posted - May 06 2005 : 06:21:37 AM
Assume Byte type for the following:
(8-bit):Make an array that has a size = (width * height)+2, Load into it the bytes that reflect the bitmap pattern itself, Make a separate array that has a size = 3*ofcolorsusedinpalette.(256 is standard)
You will need to offset each element entry by an increment of 1 inside of a loop.
i.e.

  
dim cpalette(3)  
colorsused = 128  
redim cpalette(3*colorsused) 'only half of 8-bit palette is used 'redim used for legiblity..  
pal = 1  
count = 1  
paloff = xxxx  'paloff -> palette offset, xxxx = byte number where palette information begins in bitmap  
Do until pal = done  
bytepos = count  
get #1,bytepos+paloff,r   'I could be waaay off on this.. it's been ages since I've used binary file I/O..  
get #1,bytepos+paloff+1,g  
get #1,bytepos+paloff+2,b  
cpalette(count) = r  
cpalette(count+1) = g  
cpalette(count+2) = b  
count = count + 3  
if count = 128 then pal = 0  
loop
  


To stash the pattern data itself is actually much simpler than the palette...(hint:no offsets, 1 stash element)
Also please understand I didn't take into consideration of the header size in the 8-bit bitmap format. Also
most 8-bit bitmap files are run-length compressed, I don't remember if the palette is compressed, but I know for certain that the pattern data definately is...
Additonally the above code is probably quite slow. There are ways of speeding it up I am sure.
(Pointers to the address of the array come to mind, particularly if they are used in conjunction with the virtual address of the surface you are wanting to write to.. downside would be that you'd have to lock and unlock the surface for each bitmap loaded in.. unless something changed in dx9.. not sure there.. never done any managed code.. just modular and recently semi-oo..)

http://www.wotsit.org
This site has a ton of information of various file formats to the byte. This may prove useful in being able to caculate ahead of time the header length/offset, palette length/offset, and some insight into how the pattern data is compressed. Additionally, you may even be able to take advantage of the header information to get arrays and variables setup ahead of time before going to a loop, to shorten/unroll the loop slightly..

As far as getting a pointer address for hwnd, a surface, or even an array.. best of luck.. I have no clue in VB, only in others atm.. I hope this also helps a bit...

VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.