-
Señor Member
I've got BmD to ByteArray, now the other way around?
So in my experiments with FileReference I wanted to create something cool that I had been reading about in an article: a steganographic tool.
Basically it loads an image from the user's hard drive (not using browse(), the user just specifies a URL) and they can input some text into the textbox, and click the done button. The swf then makes some changes to the bitmap to include that text secretly within the bits of the image. Then it encodes the image as a png (class I found on the internet) and brings up a save dialogue.
The next thing I want to do is use the FileReference instance I'm using to load the image file. This returns a ByteArray. Is there any way to get flash to recognize that the ByteArray contains a png and just port it automatically to a BitmapData, or would I have to search for another class that would do this for me (an unsuccessful search so far, so if anyone has seen one could you provide a link please?) instead?
Thanks for any help or info,
Mavrisa
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
Take a look at Loader.loadBytes() - that ought to parse out a bitmap to the Loader.content property. Or, check out BitmapData.setPixels().
-
Señor Member
Tried both and neither seem to work. For loadBytes, the content property is not populated. I checked that fr.data was not null (a trace returned: ‰PNG [two linebreaks] ) so that could not have been the problem. setPixels requires dimensions for the image which I do not have and don't know how to get. Perhaps I'm missing something?
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
Yea I had to really get in deep with BmD on a recent project. There is probably some way to find patterns in the bytearray which correspond to the image compression technique, but to be honest this is a bit too much. I`m not even sure if its possible. Why arent you using the Filereference.browse() then the FileReference.load() methods to access the image data. The filereference class gives you a more direct approach to image data, and the file extension for it.
-
Señor Member
I am using the fileReference class with both those methods. The problem is that when you get the data from the fileReference instance, it returns it as a byteArray, which is where my whole problem stems from. I was already using FileReference to save the file, but I had a Loader before to load the file in. Unfortunately the user had to specify the url of the file, which is somewhat more difficult than browsing around, so I wanted to switch to FileReference for loading as well.
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
Señor Member
I should probably mention that this is going to be a swf on the hosts computer, not a server.
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
I am so sure I have gone from bytearrays to bitmapdata. I will have a look when I get home tomorrow and get back to you. I remember having the same issues with things like this
-
Señor Member
Alright thank you very much
Haikus are easy
But sometimes they don't make sense
Refrigerator
-
Mav - try the loadBytes method again but wait for an Event.COMPLETE - the data should load correctly but it needs a frame for the Loader class to work it's magic between render passes.
If it helps, I've done this successfully with SWFs before - here's what it looked like:
PHP Code:
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
e.target.removeEventListener(e.type, arguments.callee);
var mc = MovieClip(e.target.content);
addChild(mc);
});
l.loadBytes(_src);
-
Señor Member
Awesome! That did it, thank you so much. I guess I didn't even think to wait for the complete event because flash already has the data, but I guess content isn't populated until complete fires.
Haikus are easy
But sometimes they don't make sense
Refrigerator
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|