Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Programming ➜ General ➜ bitmap in code

bitmap in code

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Zeno   USA  (2,871 posts)  Bio
Date Mon 20 Jun 2005 03:46 AM (UTC)

Amended on Mon 20 Jun 2005 04:31 AM (UTC) by Zeno

Message
I was wondering how an image is made into that? Like lets say I have an image I want to replace the current code with, how would I go about doing that? I'm currently working on some PSP homebrew stuff.

For example here is the code:
http://www.rebirthseph.noobify.com/icon0png.h
It makes this image:
http://img.photobucket.com/albums/v123/rebirthseph/select.jpg
(The PSP Dev white image)

Is it possible to take an image and convert it to bitmap code?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Mon 20 Jun 2005 04:26 AM (UTC)
Message
Images are nothing else than a stream of bytes. How an image is encoded in bytes depends a great deal. In your example, those could be 32-bit pixels: 8 bits R/G/B + 8 bits alpha. Or, it could be 24-bit pixels, 16-bit pixels, etc.

It looks like, based on the code, that that's a picture stored in PNG format. That makes things more complicated since PNGs are compressed, and you don't have the pixels but rather an array of bytes.

The code you posted and the code you linked to, however, aren't showing the same data.

What exactly is your question? If you have an array of bytes, you can write that to file and poof you've got an image. If you already have the image, then just open it and read it byte by byte and you'll get an in-memory representation. If you then need to make an array out of it, just print the data back out in whatever format you need.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #2 on Mon 20 Jun 2005 04:31 AM (UTC)
Message
Ignore the first bit of code, the file I linked to is what I want to change. Basically I want to replace the current image that is in the program and have it be a different one. (That is on my computer) So I'm thinking I'd have to convert the image file to code, but I'm probably wrong.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Mon 20 Jun 2005 04:40 AM (UTC)
Message
Take the array of bytes. Write it to a file. Edit that file in your image editor. Save that file; read that new file into bytes in your program. Output the file as an array hex; take outputted array of hex and stick it into the code. Make sure to update array sizes etc.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #4 on Mon 20 Jun 2005 04:43 AM (UTC)
Message
Hm, any tutorials for stuff like this? Because I never took any programming classes or anything I'm not sure about taking the array of bytes, and so on. I understood about only half of your post. :/

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Mon 20 Jun 2005 04:49 AM (UTC)
Message
Do you want to modify the image, or make a new one entirely?

Basically what you do is edit your image, save it as a .png. Then you read that file into memory, byte by byte using e.g. the read() function. You now have an array of bytes: the contents of the file. What you want to do now is take that array of bytes and turn it into a format to stick into the .h file. To do so, you output each byte as hex using printf; now you have a textual representation of the bytes. Now, you can take that and stick it into the .h file.

I don't know of any tutorials off-hand, but I'm sure you could find plenty of stuff by googling whatever trouble spots you have.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #6 on Mon 20 Jun 2005 04:53 AM (UTC)

Amended on Mon 20 Jun 2005 04:56 AM (UTC) by Zeno

Message
Well I want to replace it, so I guess I want to make a new one. I'd need an example of the read function being used to get the bytes though. I've been looking for tutorials since I've started and found nothing. I'd also need an example for the printf part. I'll look for tutorials some more.

Why I probably can't find any tutorials is because I'm not sure what to Google for.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Mon 20 Jun 2005 05:08 AM (UTC)
Message
This search brings up good references for reading bytes:
http://www.google.com/search?&q=read%20file%20bytes%20C

As for the printf, you just need to loop through every byte of the array, and use the printf specifier for hex on each byte, followed by a comma. You'd print that, copy/paste your output, and you're done.
See: http://www.rt.com/man/printf.3.htm for the right specifier.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #8 on Mon 20 Jun 2005 05:16 AM (UTC)
Message
I guess I am jumping too far in. I never really dealt with image related coding much. I think a literal example would help, but I didn't see anything in any of the tutorials so far. I'll check more stuff out tomorrow.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #9 on Mon 20 Jun 2005 05:48 AM (UTC)
Message
This isn't really image-related coding; you shouldn't think of it as such and you probably shouldn't search for anything image-related either. All you're doing here is reading and writing chunks of bytes. These bytes happen to represent a picture, but as far as your program is concerned, that is irrelevant.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #10 on Mon 20 Jun 2005 06:18 AM (UTC)

Amended on Mon 20 Jun 2005 06:23 AM (UTC) by Flannel

Message
the guts of the image aren't code, they're just bytes (guts being no header file/other bookkeeping). So, lets talk about a hypothetical image file, which happens to be black and white (only, no grey or anything). And in such, only needs one bit per pixel.

It's stored as bytes, of course but if you look at it in a bit editor (not a hex editor) you'll see the picture in 1s and 0s (provided its wrapped correctly).

That's all any bitmapped image is, just with a couple of channels instead of just black and white (and then each pixel has a range of values that it can be).

Images in code are stored (precompiled) as an array of hex numbers, since they correspond to the bytes in the file, but once they are compiled (it's only an array of hex values since that's an easy way to get a specific series of bytes into your program and reference it in your program, just like a string (and a string would work with less typing, if it werent for unprintable characters)), if you took an image editor to the correct offset of your file, you'd basically just see the image inside of your file (barring any issues with big/little endian).

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #11 on Mon 20 Jun 2005 03:36 PM (UTC)
Message
Well I found a program the devs used, so it's okay now. Good thing I'm taking C++ classes this year. :P

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


25,125 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.