MadJik Posted February 29, 2008 Share Posted February 29, 2008 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! Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted February 29, 2008 Share Posted February 29, 2008 Are you trying to find a way to create a filetype plugin? Quote Link to comment Share on other sites More sharing options...
MadJik Posted February 29, 2008 Author Share Posted February 29, 2008 Yes I am ! I'm learning c# so I need a first simple working code to make my own from it... Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
I Like Pi Posted February 29, 2008 Share Posted February 29, 2008 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); } Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted February 29, 2008 Share Posted February 29, 2008 Try my FileType template. Quote Link to comment Share on other sites More sharing options...
MadJik Posted February 29, 2008 Author Share Posted February 29, 2008 Thank you sabrown100 & I Like Pi I need to test further more... Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
MadJik Posted March 1, 2008 Author Share Posted March 1, 2008 That's what I'm able to do with the effect version: (I've replaced the 0 by space and 1 by # and use the fixed size font courrier) Model: Document: Texte file: Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted March 1, 2008 Share Posted March 1, 2008 Anyway, havn't I already written a plugin to do this? Quote Link to comment Share on other sites More sharing options...
MadJik Posted March 1, 2008 Author Share Posted March 1, 2008 I've only find this one... viewtopic.php?f=16&t=3481&start=0&st=0&sk=t&sd=a Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted March 1, 2008 Share Posted March 1, 2008 here Quote Link to comment Share on other sites More sharing options...
MadJik Posted March 1, 2008 Author Share Posted March 1, 2008 Yes, it's exactly the same idea. But in my case the binary representation is an option and the first aim is to create an hexadecimal coding. Could you share the source ? It will help me a lot to learn. And so as it's a specific plugin I won't publish mine. Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted March 1, 2008 Share Posted March 1, 2008 I need to update it really. Its fairly simple. It just goes through each pixel, converts it to b/w and if the value is above a certain number it adds one carechter to the text, if not, another. Quote Link to comment Share on other sites More sharing options...
MadJik Posted March 1, 2008 Author Share Posted March 1, 2008 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! Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted March 1, 2008 Share Posted March 1, 2008 The IO fuctions? Do you just mean how to read and write files? Quote Link to comment Share on other sites More sharing options...
MadJik Posted March 1, 2008 Author Share Posted March 1, 2008 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 Quote My DeviantArt | My Pictorium | My Plugins | Donate via Paypal Link to comment Share on other sites More sharing options...
Simon Brown Posted March 1, 2008 Share Posted March 1, 2008 The code reflixi generates is always bad. You need to instead use the Stream class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.