線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4837
推到 Plurk!
推到 Facebook!

請問如何做 URL2JPEG 這種程式?

答題得分者是:qoo1234
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-02-01 15:40:23 IP:210.241.xxx.xxx 未訂閱
請問如何做 URL2JPEG 這種程式?
http://www.url2jpeg.com/

不捲頁自動把網頁全部內容抓成圖片

------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-02-04 15:34:58 IP:211.76.xxx.xxx 未訂閱
bugmans
高階會員


發表:95
回覆:322
積分:188
註冊:2003-04-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-02-04 16:05:16 IP:125.225.xxx.xxx 未訂閱
我之前也有注意到這個問題,在ktop問過的問題但沒有解答
http://delphi.ktop.com.tw/board.php?cid=168&fid=920&tid=26538
http://delphi.ktop.com.tw/board.php?cid=168&fid=920&tid=80320
我到google找到的解答有兩種
1.取得IHTMLElementRender的Interface,再呼叫DrawToDC將網頁轉成圖
qoo1234所提供的網址就是這種方法

2.取得IViewObject2的Interface,再呼叫Draw將網頁轉成圖
我找到一個開放原始碼的軟體可以將網頁轉成圖檔
http://iecapt.sourceforge.net/
我嚐試將程式碼轉成bcb的寫法,雖然可以轉圖成功,但取得網頁的寬和高卻有錯誤
造成轉成的圖檔會出現Scroll Bar,到目前為止我還無法解決
<textarea class="cpp" rows="10" cols="60" name="code"> void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender, LPDISPATCH pDisp, Variant *URL) { IHTMLDocument3* pDocument3 = NULL; IHTMLDocument2* pDocument = NULL; IHTMLElement2* pElement2 = NULL; IHTMLElement* pElement = NULL; IViewObject2* pViewObject = NULL; IDispatch* pDispatch = NULL; IDispatch* pWebBrowserDisp = NULL; HRESULT hr; long bodyHeight; long bodyWidth; long rootHeight; long rootWidth; /*hr = m_pWebBrowser->get_Document(&pDispatch); if (FAILED(hr)) return true;*/ /*hr = m_pWebBrowserUnk->QueryInterface(IID_IDispatch, (void**)&pWebBrowserDisp); if (FAILED(hr)) return true; if (pWebBrowserDisp != pdisp) { pWebBrowserDisp->Release(); return false; }*/ pDispatch=CppWebBrowser1->Document; hr = pDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); //if (FAILED(hr)) // return true; hr = pDocument->get_body(&pElement); IHTMLBodyElement *pBodyElement=NULL; pElement->QueryInterface(IID_IHTMLBodyElement,(void **)&pBodyElement); pBodyElement->put_scroll(L"no"); //if (FAILED(hr)) // return true; hr = pElement->QueryInterface(IID_IHTMLElement2, (void**)&pElement2); //if (FAILED(hr)) // return true; long clientHeight; hr = pElement2->get_clientHeight(&clientHeight); hr = pElement2->get_scrollHeight(&bodyHeight); //if (FAILED(hr)) // return true; long clientWidth; hr = pElement2->get_clientWidth(&clientWidth); hr = pElement2->get_scrollWidth(&bodyWidth); //if (FAILED(hr)) // return true; hr = pDispatch->QueryInterface(IID_IHTMLDocument3, (void**)&pDocument3); //if (FAILED(hr)) // return true; hr = pDocument3->get_documentElement(&pElement); //if (FAILED(hr)) // return true; hr = pElement->QueryInterface(IID_IHTMLElement2, (void**)&pElement2); //if (FAILED(hr)) // return true; hr = pElement2->get_clientHeight(&clientHeight); hr = pElement2->get_scrollHeight(&rootHeight); //if (FAILED(hr)) // return true; hr = pElement2->get_clientWidth(&clientWidth); hr = pElement2->get_scrollWidth(&rootWidth); //if (FAILED(hr)) // return true; width = bodyWidth; height = rootHeight > bodyHeight ? rootHeight : bodyHeight; //MoveWindow(0, 0, width, height, TRUE); //::MoveWindow(m_hwndWebBrowser, 0, 0, width, height, TRUE); //::MoveWindow(CppWebBrowser1->Handle , 0, 0, width, height, TRUE); CppWebBrowser1->Width=width 100;CppWebBrowser1->Height=height 100; //hr = m_pWebBrowser->QueryInterface(IID_IViewObject2, (void**)&pViewObject);*/ hr = pDocument->QueryInterface(IID_IViewObject2, (void**)&pViewObject); //if (FAILED(hr)) // return true; BITMAPINFOHEADER bih; BITMAPINFO bi; RGBQUAD rgbquad; ZeroMemory(&bih, sizeof(BITMAPINFOHEADER)); ZeroMemory(&rgbquad, sizeof(RGBQUAD)); bih.biSize = sizeof(BITMAPINFOHEADER); bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = 24; bih.biClrUsed = 0; bih.biSizeImage = 0; bih.biCompression = BI_RGB; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; bi.bmiHeader = bih; bi.bmiColors[0] = rgbquad; //HDC hdcMain = GetDC(); HDC hdcMain = GetDC(Handle); //if (!hdcMain) // return true; HDC hdcMem = CreateCompatibleDC(hdcMain); //if (!hdcMem) // return true; char* bitmapData = NULL; HBITMAP hBitmap = CreateDIBSection(hdcMain, &bi, DIB_RGB_COLORS, (void**)&bitmapData, NULL, 0); //if (!hBitmap) { // TODO: cleanup // return true; //} SelectObject(hdcMem, hBitmap); RECTL rcBounds = { 0, 0, width, height }; hr = pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, hdcMain, hdcMem, &rcBounds, NULL, NULL, 0); if (SUCCEEDED(hr)) { /*CImage image; image.Create(width, height, 24); CImageDC imageDC(image); ::BitBlt(imageDC, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); image.Save(m_fileName);*/ Graphics::TBitmap *bitmap=new Graphics::TBitmap; bitmap->Width=width; bitmap->Height=height; ::BitBlt(bitmap->Canvas->Handle, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); bitmap->SaveToFile("C:\\a.bmp"); delete bitmap; } DeleteObject(hBitmap); DeleteDC(hdcMem); pViewObject->Release(); //pWebBrowserDisp->Release(); //return true; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { //::MoveWindow(CppWebBrowser1->Handle , 0, 0, width, height, TRUE); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { CppWebBrowser1->Navigate(WideString("http://delphi.ktop.com.tw")); } //--------------------------------------------------------------------------- </textarea>
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-02-05 14:51:50 IP:61.219.xxx.xxx 未訂閱
這個只能存成 BMP, 不過至少可以存成圖片了, THX
===================引 用 文 章===================
http://www.delphipages.com/tips/thread.cfm?ID=292
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
yeahe83
一般會員


發表:3
回覆:2
積分:1
註冊:2007-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-03-13 15:33:15 IP:202.103.xxx.xxx 訂閱
我想問在C++builder中如何使用到DrawToDC。没有找到含IHTMLElementRender的.H文件?
bugmans
高階會員


發表:95
回覆:322
積分:188
註冊:2003-04-12

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-03-13 18:27:43 IP:125.225.xxx.xxx 未訂閱
第一種方法我也曾用bcb寫過,IHTMLElementRender.h我在下面連結找到的
http://www.google.com.tw/search?hl=zh-TW&q=__IHTMLElementRender_FWD_DEFINED__&meta=
搜尋結果第一篇就是
yeahe83
一般會員


發表:3
回覆:2
積分:1
註冊:2007-03-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-03-14 14:10:57 IP:218.18.xxx.xxx 訂閱
bcb6的mshtml.h版本太老,不含IHTMLElementRender 的定義,我查了VS2005Team的該頭文件是有這個定義的,就直接連在了上面。
目前出現的是其他問題....

IHTMLElement *pElement = (IHTMLElement *) NULL;
IHTMLElementRender *pRender = (IHTMLElementRender *) NULL;
pElement->QueryInterface(IID_IHTMLElementRender, (void **) &pRender); // <------------这句link错误,不知何故.........
pRender->DrawToDC(GetDC(bmp->Canvas->Handle));

系統時間:2024-05-03 15:09:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!