1

I need to transfer image byte contents from JavaScript to a COM component. I will figure out the COM part but how do I get the binary image having a reference to <IMG>?

I need to support IE6+ only.

I am free to re-download the image if necessary given the source. It is not necessary to use the already downloaded image.

Is there a downloadToBytes() function or similar?

wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
  • 1
    This link might give you an idea: http://stackoverflow.com/questions/934012/get-image-data-in-javascript – Icarus Oct 06 '11 at 21:06
  • Yes thanks, I have seen that. But it uses HTML5, does it not? I need something simple. – wpfwannabe Oct 06 '11 at 21:11
  • I don't believe there is any method prior to the HTML5 methods for doing that. Your only real solution would be to pass the URL to the COM component. – Orbling Oct 06 '11 at 21:15
  • @wpfwannabe - although the answers to the other question do use modern browser technologies, there are hacks for IE (even IE6) that can get it to support some of them. I don't know specifically how well any of them would solve your question since I haven't had to work with IE6 in year (thank goodness), but it might be worth googling a bit to find out. – Spudley Oct 06 '11 at 21:15
  • 1
    @Spudley - Thanks! I have been googling and now I've turned to the community. I do have one workaround that might to the trick but I am not sure yet. It does not feature JavaScript though. I am passing a plain image URL to my COM component and using `URLDownloadToCacheFile()` to get a cached disk copy of the image. For some images I have tried works nicely. It will probably fail for images that are not cached. – wpfwannabe Oct 06 '11 at 21:21

1 Answers1

2

The only thing I could think of is the use of ajax(redownloading the image)

var src = document.getElementById('theImage').src;

var ajax = new XMLHttpRequest();
ajax.open("GET", src, true);
ajax.responseType = "arraybuffer";

ajax.onload = function () {
    var bAr = new Uint8Array(ajax.response);
    for (var i = 0; i < bAr.length; i++) {  
        //Modify binary?
    }
}

ajax.send();

The only bad thing if that the image has to have cross domain permissions if it's external. Or you can execute it from a content script which doesn't have that limit(website page must be included in the permissions value in the manifest)

jscripter
  • 840
  • 1
  • 11
  • 23