Jump to content

Image to texte file in hexa


MadJik
 Share

Recommended Posts

I'm trying to save the image as texte file in binary or hexa.

I've done it as a effect plugin for hexa and it works!

I've some guide lines from Rick and Pyrochild to transform as a file type plugin.

I've used it to scan a logo and create a hexa string (a file) for a thermal printer for labels.

It works fine (the effect plugin) with a black image on a transparent background.

Now I would like to adapt the code to have a file type plugin instead.

...and add binary conversion option...

Any help will be appreciate!

Link to comment
Share on other sites

For WriteLine, wrap the stream using StreamWriter sw = new StreamWriter(output).

To convert to and from hex, invoke px.ToHexString() or uint.Parse(hex string, NumberStyles.HexNumber);

To convert to and from binary, use bitwise operations:

StreamWriter streamWriter = new StreamWriter(output);
byte r = clr.R;
for (int bit = 7; bit >= 0; bit--) {
   Console.Write(((r & (1 << bit)) == (1 << bit)) ? 1 : 0);
}

Link to comment
Share on other sites

I know this part, I'm more interessed in the I/O functions...

I'm following the advice I got to use reflector. So it's fine enough for my needs.

If you want to update yours, may I suggest to add a slider for the level ("the certain number"). And how could we affect the preview to simulate a B/W image?

I've done it on my effect version!

Link to comment
Share on other sites

In fact yes! :oops:

With your earlier instruction "StreamWriter streamWriter = new StreamWriter(output);"

I only got zeros!

The best method I've find is from your plugin (using reflector)

 byte[] buffer = new byte[str.Length];
   for (int j = 0; j < str.Length; j++)
   {
       buffer[j] = (byte) str[j];
   }
   output.Write(buffer, 0, str.Length);

So I can adapt it. But now, I think I (we) need a B/W preview.

For now I'm able to create the text file I need for my labels: great!

I won't go further on this plugin as your ASCIIArt is what I could do to improve mine, what for then?...

Thanks to all especially to you, sabrown100

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...