<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bild aus HTML-Document extrahieren (Speichern unter...)]]></title><description><![CDATA[<p>Hi Alle,</p>
<p>Ich habe mich ja in der letzten Zeit mal mit dem CppWebBrowser und IHTMLCollections usw. beschäftigt.</p>
<p>Die Bedienelemente und deren Eigenschaften aus einer HTML Seite zu extrahieren ist mir soweit ganz gut gelungen. Ich möchte jetzt über einen Dialog einzelne Bilder des HTML Documentes auf Festplatte saven, dazu habe ich folgendes probiert:</p>
<pre><code class="language-cpp">void __fastcall TfrmMain::SaveimageClick(TObject *Sender)
{
     IHTMLImgElement *SelElement;
     TJPEGImage *JPEGImage = new TJPEGImage;
     TMemoryStream *mStream = new TMemoryStream();

     if (SelImageItem)
     {
        try
        {
           SelElement = (IHTMLImgElement*)SelImageItem-&gt;Data;

           if (SelElement)
           {
              // das Image (SelElement) in den Stream kopieren
              mStream-&gt;Write(SelElement, 21208);
              // Image in JPEG laden
              JPEGImage-&gt;LoadFromStream(mStream);
              JPEGImage-&gt;SaveToFile(&quot;c:\\test.jpg&quot;); // und saven
           }
           else MessageDlg(&quot;No element available.&quot;, mtInformation, TMsgDlgButtons() &lt;&lt; mbOK, 0);
        }
        catch ( ... )
        {
              MessageDlg(&quot;Error changing element.&quot;, mtError, TMsgDlgButtons() &lt;&lt; mbOK, 0);
        }
     }

     delete JPEGImage;
     delete mStream;
}
</code></pre>
<p>Jo, leider ist es dann doch nicht so einfach wie gedacht. SelElement enthält nur eigenschaften des HTMLImages, hat aber keinen Zeiger auf die ImageResource an sich. Sowas muss es doch aber geben, da der Explorer ja auch mit &quot;Speichern unter ...&quot; Bilder speichern kann.</p>
<p>Wie kann ich sowas programmieren, mir fehlt die zündende Idee. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/80321/bild-aus-html-document-extrahieren-speichern-unter</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 00:32:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/80321.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Jul 2004 09:10:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Tue, 20 Jul 2004 09:10:26 GMT]]></title><description><![CDATA[<p>Hi Alle,</p>
<p>Ich habe mich ja in der letzten Zeit mal mit dem CppWebBrowser und IHTMLCollections usw. beschäftigt.</p>
<p>Die Bedienelemente und deren Eigenschaften aus einer HTML Seite zu extrahieren ist mir soweit ganz gut gelungen. Ich möchte jetzt über einen Dialog einzelne Bilder des HTML Documentes auf Festplatte saven, dazu habe ich folgendes probiert:</p>
<pre><code class="language-cpp">void __fastcall TfrmMain::SaveimageClick(TObject *Sender)
{
     IHTMLImgElement *SelElement;
     TJPEGImage *JPEGImage = new TJPEGImage;
     TMemoryStream *mStream = new TMemoryStream();

     if (SelImageItem)
     {
        try
        {
           SelElement = (IHTMLImgElement*)SelImageItem-&gt;Data;

           if (SelElement)
           {
              // das Image (SelElement) in den Stream kopieren
              mStream-&gt;Write(SelElement, 21208);
              // Image in JPEG laden
              JPEGImage-&gt;LoadFromStream(mStream);
              JPEGImage-&gt;SaveToFile(&quot;c:\\test.jpg&quot;); // und saven
           }
           else MessageDlg(&quot;No element available.&quot;, mtInformation, TMsgDlgButtons() &lt;&lt; mbOK, 0);
        }
        catch ( ... )
        {
              MessageDlg(&quot;Error changing element.&quot;, mtError, TMsgDlgButtons() &lt;&lt; mbOK, 0);
        }
     }

     delete JPEGImage;
     delete mStream;
}
</code></pre>
<p>Jo, leider ist es dann doch nicht so einfach wie gedacht. SelElement enthält nur eigenschaften des HTMLImages, hat aber keinen Zeiger auf die ImageResource an sich. Sowas muss es doch aber geben, da der Explorer ja auch mit &quot;Speichern unter ...&quot; Bilder speichern kann.</p>
<p>Wie kann ich sowas programmieren, mir fehlt die zündende Idee. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/564264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564264</guid><dc:creator><![CDATA[F98]]></dc:creator><pubDate>Tue, 20 Jul 2004 09:10:26 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Tue, 20 Jul 2004 21:31:15 GMT]]></title><description><![CDATA[<p>eigenschaften sollten genügen. Sie müssten auch den Dateinamen enthalten, mit dem kannst du sehr viel anfangen... z.B. nimm eine TIdHTTP-Komponente und lade das Bild dann herunter...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564774</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564774</guid><dc:creator><![CDATA[Windoof]]></dc:creator><pubDate>Tue, 20 Jul 2004 21:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Tue, 20 Jul 2004 22:02:05 GMT]]></title><description><![CDATA[<p>Ich gehe mal davon aus, dass F98 <strong>das</strong> selber wusste.<br />
Der Punkt ist aber, das bereits geladene Bild nicht nochmal laden zu müssen.</p>
<p>In Delphi gibt es offenbar die Möglichkeit, über die <a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;ie=UTF-8&amp;threadm=6h57rh%248t46%40forums.borland.com&amp;rnum=4&amp;prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26q%3Dwebbrowser%2Bsave%2Bimage%26btnG%3DSearch%26meta%3Dgroup%253Dborland.public.*" rel="nofollow">OleObject-Property</a> da ranzukommen (letzte Beiträge), ich kann mich allerdings an eine ähnliche Diskussion hier erinnern, nach der dieses Vorgehen beim <strong>Cpp</strong>WebBrowser nicht möglich ist. Auf jeden Fall gibt es da schon mal kein OleObject.Document ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564796</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564796</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Tue, 20 Jul 2004 22:02:05 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Wed, 21 Jul 2004 08:11:01 GMT]]></title><description><![CDATA[<p>Jo, CppWebBrowser hat kein OleObject-&gt;Document. Ich hatte mir gedacht es über IHTMLDocument zu versuchen, aber IHTMLDocument hat auch keine Images sondern nur eine Funktion get_images() die eine IHTMLElementCollection übergeben haben will. Wenn mann die durchwühlt kommt man zwar an die Imageeigenschaften (src, height ...) ran, aber nicht an die entsprechende Resource.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564936</guid><dc:creator><![CDATA[F98]]></dc:creator><pubDate>Wed, 21 Jul 2004 08:11:01 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Wed, 21 Jul 2004 08:47:45 GMT]]></title><description><![CDATA[<p>Ich habe jetzt folgendes gefunden:</p>
<p><a href="http://groups.google.com/groups?hl=en&amp;lr=&amp;ie=UTF-8&amp;threadm=3f66abe6%241%40newsgroups.borland.com&amp;rnum=1&amp;prev=/groups%3Fq%3Dcppwebbrowser%2Bimage%2Bgroup:borland.public.cppbuilder.*%26hl%3Den%26lr%3D%26ie%3DUTF-8%26group%3Dborland.public.cppbuilder.*%26selm%3D3f66abe6%25241%2540newsgroups.borland.com%26rnum%3D1" rel="nofollow">Google Group</a></p>
<p>IHTMLImgElement does not provide you access to either the locally stored<br />
file or its actual data. For that, you will just have to find the image<br />
file in the browser's cache manually and then copy the file to the new<br />
location. You can use the IHTMLImgElement::src property to get the URL for<br />
the image, and then use RetrieveUrlCacheEntryFile() to retreive the local<br />
filename that it is cached as. Then you can use CopyFile() to copy it to<br />
your desired destination folder.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/564969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/564969</guid><dc:creator><![CDATA[F98]]></dc:creator><pubDate>Wed, 21 Jul 2004 08:47:45 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Tue, 03 Aug 2004 14:25:48 GMT]]></title><description><![CDATA[<p>noch folgende Frage: Wie komme ich an die URL heran, auf die ein Bild zeigt, wenn es folgendermaßen eingebaut ist:</p>
<pre><code>&lt;a href=&quot;http://www.heise.de&quot;&gt;&lt;img src=&quot;/icons/ho/heise.gif&quot; alt=&quot;heise online&quot;&gt;&lt;/a&gt;
</code></pre>
<p>Ich muß also das vorherige oder übergeordnete Objekt wiederfinden, welches dann wohl ein IHTMLAnchorElement ist, aber wie geht das?</p>
<p>Ich finde das Bild, auf das geklickt wurde, folgendermaßen heraus:</p>
<pre><code class="language-cpp">AnsiString TAcDocHandler::getImageUnderMouse(POINT mousePos, AnsiString* imgLinkTo) {
  AnsiString url = &quot;&quot;;
  TCppWebBrowser *wbMain = browser;
  IHTMLDocument2 *pDoc = NULL;
  IHTMLElement *pElement = NULL;
  IHTMLImgElement *pImage = NULL;
  bool blUrl = false;

  try
  {
    if(wbMain-&gt;Document == NULL)
      return &quot;&quot;;

    WideString wURL;
    WideString wImgUrl;
    POINT p = mousePos;

    if(SUCCEEDED(wbMain-&gt;Document-&gt;QueryInterface(IID_IHTMLDocument2,(LPVOID*)&amp;pDoc)))
    {
      if(pDoc == NULL)
        return &quot;&quot;;

      //GetCursorPos(&amp;p);
      p = wbMain-&gt;ScreenToClient(p);
      if(SUCCEEDED(pDoc-&gt;elementFromPoint(p.x, p.y, &amp;pElement)))
      {
        if(pElement == NULL)
          return &quot;&quot;;

        if(SUCCEEDED(pElement-&gt;QueryInterface(IID_IHTMLImgElement,(LPVOID*)&amp;pImage)))
        {
          if(pImage == NULL)
            return &quot;&quot;;

          if(SUCCEEDED(pImage-&gt;get_src(&amp;wURL)))
          {
            blUrl = true;
            url = AnsiString(wURL);
          }
        }
      }
    }
  }
  __finally
  {
    if(!blUrl)
      url = &quot;&quot;;
    if(pDoc != NULL)
      pDoc-&gt;Release();
    if(pElement != NULL)
      pElement-&gt;Release();
    if(pImage != NULL)
      pImage-&gt;Release();
    return url;
  }
}
</code></pre>
<p>Aber wie bekomme ich jetzt das IHTMLAnchorElement heraus, in diesem Fall &quot;<a href="http://www.heise.de" rel="nofollow">http://www.heise.de</a>&quot;?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/574399</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/574399</guid><dc:creator><![CDATA[Ickis]]></dc:creator><pubDate>Tue, 03 Aug 2004 14:25:48 GMT</pubDate></item><item><title><![CDATA[Reply to Bild aus HTML-Document extrahieren (Speichern unter...) on Wed, 04 Aug 2004 06:11:41 GMT]]></title><description><![CDATA[<p>Ich habe mir extrahieren des Seiteninhalts folgende Funktionen umgesetzt:</p>
<pre><code class="language-cpp">// Seiteninhalt für jedes Frame zerflücken
bool __fastcall TfrmMain::GetHTMLElements()
{
     IHTMLDocument2 *HTMLDocument = NULL;
     LONG ilFramesCount = 0;
     bool bretVal = true;

     try
     {
        if (WebBrowserWin-&gt;Document)
        {
           sbStatus-&gt;SimpleText = &quot;All HTML data from &quot;+cbURL-&gt;Text+&quot; received&quot;;

           lvFormElements-&gt;Items-&gt;Clear();
           lvImageElements-&gt;Items-&gt;Clear();
           lvInputElements-&gt;Items-&gt;Clear();
           lvURL-&gt;Items-&gt;Clear();

           // Falls eine Seite geladen:
           if (SUCCEEDED(WebBrowserWin-&gt;Document-&gt;QueryInterface(IID_IHTMLDocument2, (LPVOID*)&amp;HTMLDocument)))
           {
              if (HTMLDocument != NULL)
              {
                 IHTMLFramesCollection2 *pFrames = NULL;
                 if (SUCCEEDED(HTMLDocument-&gt;get_frames(&amp;pFrames)))
                 {
                    // Anzahl der Frames bestimmen:
                    pFrames-&gt;get_length(&amp;ilFramesCount);
                    // wenn nur ein Frame
                    if (ilFramesCount &lt; 2) GetFrameContent(HTMLDocument);
                    else
                    {
                        VARIANT vFrame;
                        VariantInit(&amp;vFrame);
                        vFrame.vt = VT_UINT;
                        vFrame.lVal = 0;

                        VARIANT vRet;
                        VariantInit(&amp;vRet);
                        vRet.vt = VT_UINT;
                        vRet.lVal = 0;

                        // ansonsten für jedes Frame einzeln:
                        for (LONG ilFrameIndex = 0; ilFrameIndex &lt; ilFramesCount; ilFrameIndex++)
                        {
                            vFrame.lVal = ilFrameIndex;
                            if (SUCCEEDED(pFrames-&gt;item(&amp;vFrame, &amp;vRet)))
                            {
                               IHTMLWindow2 *pWindow = NULL;
                               if (SUCCEEDED(vRet.pdispVal-&gt;QueryInterface(IID_IHTMLWindow2, (LPVOID*)&amp;pWindow)))
                               {
                                  IHTMLDocument2 *pDoc = NULL;
                                  if (SUCCEEDED(pWindow-&gt;get_document(&amp;pDoc)))
                                  {
                                     GetFrameContent(pDoc);
                                     pDoc-&gt;Release();
                                  }

                                  pWindow-&gt;Release();
                               }
                            }
                        }

                        VariantClear(&amp;vFrame);
                        VariantClear(&amp;vRet);
                    }
                    pFrames-&gt;Release();
                 }

                 HTMLDocument-&gt;Release();
              }
           }

           tbRescan-&gt;Enabled = true;
        }
     }
     catch ( Exception &amp;E )
     {
           MessageDlg(E.Message, mtError, TMsgDlgButtons() &lt;&lt; mbOK, 0);
           bretVal = false;
     }

     return bretVal;
}

bool __fastcall TfrmMain::GetFrameContent(IHTMLDocument2 *HTMLDocument)
{
     IHTMLElementCollection *pAll = NULL;
     TListItem *ListItem;
     bool bretVal = true;

     try
     {
        if (HTMLDocument != NULL)
        {
           if (SUCCEEDED(HTMLDocument-&gt;get_all(&amp;pAll)) &amp;&amp; pAll)
           {
              long iColLengh;
              pAll-&gt;get_length(&amp;iColLengh);

              for (long i=0; i&lt;iColLengh; i++)
              {
                  VARIANT vIndex;
                  VariantInit(&amp;vIndex);
                  vIndex.vt = VT_UINT;
                  vIndex.lVal = i;

                  IDispatch *pDisp = NULL;

                  // erstmal ein Item holen
                  if (SUCCEEDED(pAll-&gt;item(vIndex, vIndex, &amp;pDisp)) &amp;&amp; pDisp)
                  {
                     IHTMLInputElement *pInput = NULL;
                     IHTMLFormElement *pForm = NULL;
                     IHTMLImgElement *pImg = NULL;
                     IHTMLAnchorElement *pAnchor = NULL;

                     WideString wsElementName;
                     WideString wsElementValue;
                     WideString wsElementType;
                     WideString wsElementForm;
                     WideString wsElementSize;
                     WideString wsElementSrc;
                     WideString wsElementAction;
                     WideString wsElementHREF;

                     // ist es ein Inputelement (Edit)?
                     if (SUCCEEDED(pDisp-&gt;QueryInterface(IID_IHTMLInputElement, (LPVOID*)&amp;pInput)) &amp;&amp; pInput)
                     {
                        IHTMLFormElement *pTempForm = NULL;
                        pInput-&gt;get_name(&amp;wsElementName);
                        pInput-&gt;get_value(&amp;wsElementValue);
                        pInput-&gt;get_type(&amp;wsElementType);
                        pInput-&gt;get_form(&amp;pTempForm);
                        if (pTempForm) pTempForm-&gt;get_name(&amp;wsElementForm);

                        ListItem = lvInputElements-&gt;Items-&gt;Add();
                        ListItem-&gt;Caption = wsElementName;
                        ListItem-&gt;SubItems-&gt;Add(wsElementForm);
                        ListItem-&gt;SubItems-&gt;Add(wsElementType);
                        ListItem-&gt;SubItems-&gt;Add(wsElementValue);
                        ListItem-&gt;Data = pInput;
                     }
                     else
                     {
                         // oder ein Formularelement (Button) ?
                         if (SUCCEEDED(pDisp-&gt;QueryInterface(IID_IHTMLFormElement, (LPVOID*)&amp;pForm)) &amp;&amp; pForm)
                         {
                            AnsiString sTempName;
                            AnsiString sTempAction;

                            pForm-&gt;get_name(&amp;wsElementName);
                            pForm-&gt;get_action(&amp;wsElementAction);

                            sTempName = wsElementName;
                            sTempAction = wsElementAction;

                            if ((!sTempName.IsEmpty()) &amp;&amp; (!sTempAction.IsEmpty()))
                            {
                               ListItem = lvFormElements-&gt;Items-&gt;Add();
                               ListItem-&gt;Caption = wsElementName;
                               ListItem-&gt;SubItems-&gt;Add(wsElementAction);
                               ListItem-&gt;Data = pForm;
                            }
                         }
                         else
                         {
                             // ein Image?
                             if (SUCCEEDED(pDisp-&gt;QueryInterface(IID_IHTMLImgElement, (LPVOID*)&amp;pImg)) &amp;&amp; pImg)
                             {
                                pImg-&gt;get_name(&amp;wsElementName);
                                pImg-&gt;get_src(&amp;wsElementSrc);
                                pImg-&gt;get_fileSize(&amp;wsElementSize);
                                AnsiString sTempName = wsElementName;

                                if (sTempName.IsEmpty()) sTempName = &quot;empty&quot;;
                                ListItem = lvImageElements-&gt;Items-&gt;Add();
                                ListItem-&gt;Caption = sTempName;
                                ListItem-&gt;SubItems-&gt;Add(wsElementSrc);
                                ListItem-&gt;SubItems-&gt;Add(wsElementSize);
                                ListItem-&gt;Data = pImg;
                             }
                             else
                             {
                                 // oder eine URL?
                                 if (SUCCEEDED(pDisp-&gt;QueryInterface(IID_IHTMLAnchorElement, (LPVOID*)&amp;pAnchor)))
                                 {
                                    if (SUCCEEDED(pAnchor-&gt;get_href(&amp;wsElementHREF)))
                                    {
                                       ListItem = lvURL-&gt;Items-&gt;Add();
                                       ListItem-&gt;Caption = wsElementHREF;
                                       ListItem-&gt;Data = pAnchor;
                                    }
                                 }
                             }
                         }
                     }

                     pDisp-&gt;Release();
                  }

                  VariantClear(&amp;vIndex);
              }

              pAll-&gt;Release();
           }
        }
     }
     catch ( Exception &amp;E )
     {
           MessageDlg(E.Message, mtError, TMsgDlgButtons() &lt;&lt; mbOK, 0);
           bretVal = false;
     }

     return bretVal;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/574785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/574785</guid><dc:creator><![CDATA[F98]]></dc:creator><pubDate>Wed, 04 Aug 2004 06:11:41 GMT</pubDate></item></channel></rss>