jpeg info from flash to javascript - javascript

I'm trying to transfer a jpeg from Flash to JavaScript. Is this even possible?
What I mean by that is: Flash is supplied an image from the user and performs some image manipulation. I then need to display that modified image in HTML. Do I need to post the image from the flash to the server and load it in html through a URL, or can I pass it directly from the flash into a javascript Image object through flash's external interface somehow?
What's the best way to do this?
Thanks.

One possible way is to encode your image to base64 and send the string via externalInterface call to JavaScript. On the JavaScript side you will need to decode the received string from base64 back to the original jpeg format.
Here a collection of tutorials to do all the bits needed:
Convert image to base64 in Actionscript: http://swati61.blogspot.de/2011/07/convert-image-to-base64-string-and-vice.html
Convert base64 to image in javascript : Base64 encoding and decoding in client-side Javascript
Communication between Actionscript and JavaScript: http://www.hariscusto.com/programming/communication-between-javascript-and-actionscript-as3-and-vice-versa/
I hope this answers your question.

Related

Convert already loaded image to base64

I have a use case to convert images to base64 using the url. But the website loads the image only once. I cannot convert to canvas since it requires a network call and is forbidden for second time.
But I am able to achieve the conversion using the sources panel in chrome which has an option to convert already loaded images to data URI. Ex: https://developers.google.com/web/updates/2015/05/copy-image-as-data-uri
I would like to do this programatically using javascript.
Either I inject a module while the image loads to convert to base64 and store it or access the sources panel in chrome to convert to data URI as it does.
I would like to know if there are any extensions to achieve this.
Thank you

How to convert Base64 encoded string to any other image formats which can be displayed in chrome browser

I have a Base64 encoded string of a TIFF image type which is not working in chrome browser so I want to convert it into a any other image formats(JPG,PNG or BMP) using java/javascript. I'm looking for either server side logic in java or client side logic in javascript.
I would like to process at server side.
You can explore this- [https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/com/sun/media/jai-codec/1.1.3/jai-codec-1.1.3.jar][1]

Convert binary / unicode string to image

I am using a library to recieve attachments (image) from salesforce using OAuth and a proxy. Without the library (and the proxy) I am able to the same using XHR, but I have to use the library because I need the proxy.
In chrome debugger I can see image is downloaded fine, but I can't get it to work in my code. Data looks like:
So far methods I have tried:
btoa(unescape(encodeURIComponent(file.body)));- produces a base64 that does not work. decoding it using online tools gives me back the same string.
escape(file.body) - using this as base64 also does not work.
Converting to a blob.
var blob = new Blob([file.body], {type : "image/png"});
urlCreator.createObjectURL(blob);
The url it points to displays nothing, and if I remove {type : "image/png"} the url points to a page displaying same binary string.
Long story short this looks like someone read the image with readAsText() which mangles ("interprets") binary into utf8, instead of utf16. You need to get the server to return the data in arraybuffer or blob format ideally, or even base64, these preserve binary.
Long version with snippet. (those question marks symbols in the snippet show the lost information, compare it to the binary where they are not question marks in utf16):
https://stackoverflow.com/a/56523118/2962797
I would create an <img /> element, equal its src attribute to the image data you received. Now you have the image.
If you want to extract it or convert it to PNG, I would apply this another answer process.

how to get data from a base64 encoding of a .pptx file in javascript

I get data from a server of the .pptx file in base64 encoding now i would like to get the text that is present inside the base64 data.
Is there any third party java script library to do this especially scanning in base64 code rather than taking the file path and i would like insert these strings into a power point using office js.
Client side would be preferred.
thanks
Seems that what you need is a JavaScript decoder for base64 files, there are many projects in Github Doing this, for instance here is one https://github.com/mathiasbynens/base64.
That said, I am not sure about your scenario, and what types of files are been base64-encoded. Base64 at the end of the day is a text "representation" of usually a binary file, like an image or a compressed zip file. I wonder if once you decode it you will get what you expect. And if you are expecting text, i wonder why your service is even encoding it like this.
Anyways... once you have whatever text you want to insert, you can use the setSelectedDataAsync method of our Office.js in PPT to write it in your presentation's active selection. https://dev.office.com/reference/add-ins/shared/document.setselecteddataasync

Transfer bitmap from Flash movie to Javascript

I would like to know what is the most efficient way to transfer BitmapData object from Actionscript to Javascript, so an image can be displayed on webpage.
So far, I've managed to craft a string containing image data using data URI scheme in Flash and then I transfered it to the Javascript using ExternalInterface.call("<function_name>", data).
While it is working fine, it seems wasteful to convert image to its textual representation just to transfer it. Is there a cleaner/more efficient way to achieve the same?
AS3:
base64 encode your BitmapData object. example
then:
ExternalInterface.call("setImage",encodedImg);
Javascript:
function setImage(baseSixtyFourEncodedImage)
{
document.getElementById("myImage").src = "data:" + baseSixtyFourEncodedImage;
}
HTML:
<img id="myImage" src="no_image_from_flash_yet.png">
Don't forget to import ExternalInterface on the flash end!
let me know how it goes.

Categories

Resources