how to get image from TWebBrowser into a TImage - delphi

I have a panel at the top of a form with a smallish TMemo set up as a drop target for URLs. Below that I have a Page Control with 2 tabs. I set up a TWebBrowser in one tab and some other stuff in the second tab. In the TWebBrowser, I need to login to a bug ticketing site we have, then browse tickets. Certain tickets have links to small images that clients want us to use (think something like logos). I can left-click on them and then drag-n-drop the link from the TWebBrowser to the TMemo at the top of the form. That picks up the image's URL and Title as expected.
The associated OnDrop event also switches to the 2nd tab and where I click a "Process" button. That causes the browser to navigate to the image (via Navigate2), which it loads into the browser window. That image is all that's in the browser window at this point.
So now I need the code to grab the image and load it into a TImage on the 2nd tabsheet. FWIW, the original image is a PNG.
I'm able to get the height and width of the image from the target image, but I'm not getting the image itself to show up in the TImage most of the time. Sometimes, but mostly not. I can load PNGs into these image objects just fine, so I know it displays PNGs properly.
(Maybe there's a way to do a download the image directly, but I wasn't able to get that to work. The TWebBrowser is used to login to an internal bug ticketing system where the images are being provided, and I can access that site only if it's on the same form and I've logged in. Otherwise the DL loads an HTML login page instead of the image. If there's a way to do that in the current framework, I'm open to suggestions.)
I'm finding the image file on the web page using IHTMLElement2.getelementsByTagName('img') and grabbing the first one (since I know that's all there is on the web page).
img := getFirstImage;
Image1_frame.Height := img.height+2;
Image1_frame.Width := img.width+2;
rnd := img as IHTMLElementRender ;
rnd.DrawToDC(Image1.Canvas.Handle);
Image1 is aligned to Client on a panel named Image1_frame. So I set the frame's H & W -- they get set ok.
But the image is usually not visible. It's just white.
I see that DrawToDC is deprecated, but I haven't found what to replace it with.

You can use this approach to auto login (if needed) :
Automated Log In (webBrowser)
Then you can use this to get the Image: Image from TWebBrowser to TPicture

Related

Previews in delphi?

I am creating a project in Delphi and was wondering if it was is possible to create a preview of a tab. My idea is for a person to hover over the panel that takes you to the page and then it shows a preview in the hint, like when you hover over an icon in your task bar. if this is possible, would it also be possible to display the page instead of the panel as a preview and then click on it to go there? By this I mean almost like an image of the page, but my problem is that I don't want it to be a static screenshot of the page, I want it to be able to show the page as it is, with any changes made. The same applies to the hint(I.E Not a static image).
Any help, and explanations, would be greatly appreciated.
To get the current view of a TTabSheet, you should use a function much like this one:
procedure TForm81.CopySheet(TAB: TTabSheet);
var
bmp : TBitMap;
begin
bmp:=TBitMap.Create;
try
bmp.PixelFormat:=TPixelFormat.pf24bit;
bmp.Width:=TAB.Width; bmp.Height:=TAB.Height;
TAB.PaintTo(BMP.Canvas,0,0);
// Do what you need to with the bmp, ie. show it in a hint, a preview window, etc.
finally
bmp.Free
end
end;
The essential method is the "PaintTo" on the TAB (and most other TControls), which draws itself onto a TCanvas (f.ex. of a TBitmap, like above).
I'll leave it up to you to fill out the "Do what you need to with the bmp, ie. show it in a hint, a preview window, etc." part :-)

How to access page of a multipage pdf file in Gimp?

When I open a multipage pdf file, gimp lets me select the pages I want to import. After opening the file, the first page selected appears in a file window. How do I access the other pages?
thanks
Each page is loaded as a layer. To see a page you have to make the layers above it invisible, this is done by clicking the eye icon on the left of the layer thumbnails in the Layers list.
Shift-click on the icon of a Layer toggles the visibility of all other layers, so this is a very quick way to make it visible.
If you need to put all the pages side by side, there are scripts for this, for instance ofn-layer-tiles that you will find here.

Pull div content to external display in electron

In my project, I need to achieve a very special function: pull div content to external display, div content include text, image, video, other html ..., enter image description here
You could use the screen module to detect the display and create another window and move it into there.

Windows ribbon split button gallery button image

I'm using Windows Ribbon for Delphi (from http://www.bilsen.com/windowsribbon/commands.shtml) and I have a split-button gallery, to give a drop-list of items that I can populate at runtime.
The part that isn't working is when I select an item from the gallery, its image isn't automatically transferred to the split button and I can't find a way to make it happen manually.
I've tried looking through the MS documentation but I can't see anything there that helps change the image of the button.
For the avoidance of doubt: I've checked in MSPaint and the brush selection works exactly as I want my button to work.

TWebbrowser causes AV - what to look for

I have a TWebbroser on a form wher I want to hide the scrollbars
On WebBrowser1DownloadComplete I put WebBrowser1.OleObject.document.body.scroll:='no';
But this results in an AV.
If I click continue I can see that the scrollbars are actually removed, so the code must be the right one to use.
What I am trying to do is to show a page from Google Maps with a lot of markers that I add. This page needs to be printed on an A4 page but it is to big to print directly from the TWebbrowser (or at least I can't get it to work). So I save it as an JPG image and loads that on another form, prints it using DevExpress printingsystem on A4 page with the headers and footers I want.
All is working like I want it to except the removal of the scrollbars.
For accessing Google Maps I use the gmLibrary from http://www.cadetill.com/gmlib/ - very nice lib and it has a pricetag I like.
Just put your code in the DocumentComplete event to remove the AV.
The IE HTML/CSS tricks to remove the scrollbars will not work reliable if the control is embedded. To realy remove the scrollbar you have to inherit the TWebBrowser with the IDocHostUIHandler interface. In GetHostInfo you have to set at least the DOCHOSTUIFLAG_SCROLL_NO flag.
You may consider to use one of the existing descendants like 'Embedded Web Browser Component Pack' (http://www.bsalsa.com/).

Resources