How to manipulate images?

Add-in Express™ Support Service
That's what is more important than anything else

How to manipulate images?
need access to image "as object" 
Dominik Burth




Posts: 6
Joined: 2011-01-25
Hi to all,

in my BHO I can find all images:
Dim Elems As mshtml.IHTMLElementCollection
Dim locImg As mshtml.IHTMLImgElement
Elems = HTMLDocument.getElementsByTagName("img")
For Each locImg In Elems
[...]
Next

Lets say, I find a pic coming with the site as "outdated". In memory I have already an other pic (as SystemDrawing.Image or ByteArray). Now I like to replace the incoming pic (locImg) with the pic holded in memory "on the fly", without having to save it before to the harddisc.

Is this possible? Can please anyone point me to the right way?

I'm using VB.NET on Visual Studio 2010 Pro with Add-in Express 2010 for IExplorer.
Posted 25 Jan, 2011 15:40:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Dominik.

As far as I understand, you just need change the 'src' attribute of the 'img' tag so that it points to the location with the new image. I am not aware of any other way. If I find any, I will let you know.
Posted 26 Jan, 2011 11:13:21 Top
Dominik Burth




Posts: 6
Joined: 2011-01-25
Hi Sergey,

thanks for reply.

I try to filter all jpegs with a certain Exif data. If not present, I do nothing, but if present, I like to tier out the data (lets say a thumbnail) and replace one an other.
1) I thought, having an IHtmlImgElement is like a SystemDrawing.Image - it's not. Ok, I can reload it from the server, because I have the .href, but I feel that's time wasting.
2) I deal with this jpeg in memory to get the Exif's and, lets say, the thumbnail is secret, I do not like to write it down to a harddisc.

If you have time to think about a possible way, please have 1) and 2) in mind.

Concerning your answer to 'src':
I tried out in my IEModule_DocumentComplete-Event to reset the locImg.src like
locImg.src = "C:\VBproj\Graphics\Copyright.jpg"
just to see, how this works - but no chance. Right-Click & Properties tells me the new name Copyright.jpg, but the pic shown is already the old one from the server.
How to "refresh" this?

Thanks so much for your appreciated help.
Posted 26 Jan, 2011 14:28:05 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Dominik.

I tried out in my IEModule_DocumentComplete-Event to reset the locImg.src like
locImg.src = "C:\VBproj\Graphics\Copyright.jpg"
just to see, how this works - but no chance.

I will investigate this issue and let you know about results soon.
Posted 27 Jan, 2011 11:06:57 Top
Dominik Burth




Posts: 6
Joined: 2011-01-25
Sorry Sergey,

do you have already found something, how to 'refresh' the pic?
By the way: I'm very interested too in the neighbors post 'IE has focus'.

Thanks so much,
Dominik
Posted 07 Feb, 2011 14:35:07 Top
Dominik Burth




Posts: 6
Joined: 2011-01-25
Hi,

regarding to the "pic refresh" problem, I've found out, that it is the local path IE doesn't accept. I'm looping throu all pics of a site, pic me one out and do:

[...]
locImg.src = "C:\VBproj\Graphics\Copyright.jpg"
[...]
what is not working! I tried all kind of notations like "localhost..." or "file://...." but nothing helps!

The only way to set an other image was by using a web path (http://www....).

Does anyone know a solution? Or any idea for other ways to solve the problem, to replace images with a modified, local version (original in memory or otherwise per file load)?

Thanks in advance, Dominik.
Posted 13 Feb, 2011 14:42:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Dominik.

I will get back to this subject when I take on a new build of the product. It will be in a couple of weeks. Probably I will manage to find any workaround.
Posted 14 Feb, 2011 05:28:28 Top
Sergey Grischenko


Add-in Express team


Posts: 7202
Joined: 2004-07-05
Hi Dominik.

I managed to replace an image with a new one stored on a local drive. But I had to create a Virtual Directory in IIS to make it worked. Here is the code below. It replaces the Google image when you open 'http://www.google.com'.

string imageSrc = "<img alt=\"Test\" height=16 src=\"http://localhost/testimage/myImage.gif\" width=16>";

private void IEModule_DownloadComplete()
{
HTMLDocument document = (HTMLDocument)IEApp.Document;
IHTMLElement elem = document.getElementById("hplogo");
if (elem != null)
{
elem.style.visibility = "hidden";
elem.insertAdjacentHTML("afterEnd", imageSrc);
}
}
Posted 11 Mar, 2011 16:07:07 Top