Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

ImageToCode (and CodeToImage): Embed images in class files!

Hello everyone. I've always wanted to embed small images in my themes (icons, logo's, whatever) but I hate hardcoding resource names in my classes.
Of course you can give the user some .png files and let them add them to the resources, but I wanted something better :)

This class can convert images into code (suitable for Visual Studio, I'll explain that later) and convert them back into images.
This way you can embed little icons in your class file!

Visual studio has a maximum line length of 65530 (or something like that). To prevent errors from happening I've added an option to output a VS-compatible string.

To use this, just add the class and use this code:

Convert an image into code:
Code
Dim ITC As New ImageToCodeClass
Dim Code as String =  ITC.ImageToCode(YourImage)

Convert the code into an image:
Code
Dim ITC As New ImageToCodeClass
PictureBox1.Image = ITC.CodeToImage("<YOUR IMAGE CODE HERE>")



Download:
Spoiler (Click to View)

Note: This isn't supposed to be top-notch coding. It's made to work, not made to be 100% perfect and professional. I made it for personal purposes and just decided to share this with you guys.
EDIT: Completely new class, super small yet much better. Better performance, smaller string,... Thanks for the suggestions!
saw this on youtube, really nice work

keep up mate
Where did you find out about these image codes? Never herd of them before and still not really sure why this is better?

I mean nice app and video but how? , why? lol :P
You're just getting each pixel, and logging their RGB right? :3
(Jun 11, 2012 12:59 PM)Deceptive Wrote:  You're just getting each pixel, and logging their RGB right? :3

Yea thats what I got from the pastebin link, But why? whats the benefit?

I mean why not into a byte array or something?
(Jun 11, 2012 01:02 PM)DotNetNut Wrote:  Yea thats what I got from the pastebin link, But why? whats the benefit?

I mean why not into a byte array or something?

Evidently so he doesn't have to store his images in resources.
(Jun 11, 2012 01:12 PM)Deceptive Wrote:  Evidently so he doesn't have to store his images in resources.

Oh.. ok lol, I thought it would of been easier to convert from Image > Bytearray > string?

I take it doing it that way, as i suggested above would make it a massive sting.. And also i wonder why he dose not want to store in resources? I mean is that not what their for?

I guess i just want to know if this method is actually better or ? lol.

confused... :P
(Jun 11, 2012 01:12 PM)Deceptive Wrote:  Evidently so he doesn't have to store his images in resources.

Exactly. I want to include small images into themes and still be able to just post a pastebin link.
There's probably lots of better ways to do this, and my method with splitting things probably isn't the most efficient, but it works :D
(Jun 11, 2012 01:20 PM)Meerkat. Wrote:  Exactly. I want to include small images into themes and still be able to just post a pastebin link.
There's probably lots of better ways to do this, and my method with splitting things probably isn't the most efficient, but it works :D

Right i got you know :D lol, I thought this was just a way for you to store them when making new apps lulz, But i can see the benefit of it now :P
I just tried a few of these and omg the string are fucking huge!

I tried to post one string as an example but it was apparently 16300 chars over the limit on a 60kb image lul..

EDIT : And i see you have gone to the dark side.. Enjoy your uber :D
Ahhh, another good release, will definitly have to have a play with this!
Why not just using a binarySeralizer and seralize it to a byte array and convert that to a base64 string.. I think it could take like 5 lines of code..

Anyways, gj

[Image: HJdK32K_x]
lensert.com is the new screenshot utility, try it out now!
OSX & WINDOWS

I can't call this Stenography and still. This is amazing. Thank you.
(Jun 12, 2012 03:40 AM)marvinn Wrote:  Why not just using a binarySeralizer and seralize it to a byte array and convert that to a base64 string.. I think it could take like 5 lines of code..

Anyways, gj

This is what I'd suggest too (perhaps not serializing, but just converting the image to it's byte representation and then to a Base64 string), it's how resources in Visual Studio are stored in RESX files. Iterating through each pixel isn't very efficient and uses a lot of resources, not to mention the string this produces can be rediculously large, but then again, you did explictly mention "this isn't supposed to be top-notch coding".
I like the idea, but the strings become loooonng..
Maybe you can take a look at compressing the strings with a GZip or Deflate Stream.
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lockheadApr 22, 2021 07:10 AM 0 147 Apr 22, 2021 07:10 AM
Last Post: lockhead
[Shell] by Johnny CacheJan 23, 2021 11:08 AM 3 240 Jan 23, 2021 11:08 AM
Last Post: Shellc0de™
[C] by ColossalOctopusMar 14, 2019 09:03 AM 2 165 Mar 14, 2019 09:03 AM
Last Post: 0xDEAD10CC