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

[轉檔]請問關於.RTF檔轉成.JPG檔

尚未結案
SCBT
一般會員


發表:2
回覆:3
積分:1
註冊:2004-02-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-13 16:23:37 IP:203.75.xxx.xxx 未訂閱
HI!各位先進 請問Delphi有元件或其他辦法可以將*.rtf檔轉成*.jpg檔嗎? 感謝~!
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-15 18:02:56 IP:202.39.xxx.xxx 未訂閱
能用 TRichEdit 開啟此 .rtf 檔的話 參考 "How to copy contents of a Trichedit to a BMP" 這篇: http://groups.google.com/groups?hl=zh-TW&lr=&ie=UTF-8&th=9e1bebdae16cd3d8&rnum=3    -- 向 KTop 的弟兄們致敬! 
andychang1690
資深會員


發表:20
回覆:694
積分:442
註冊:2003-03-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-15 21:56:52 IP:219.130.xxx.xxx 未訂閱
程式倒不大,短短幾十行而已,可惜我只會C++Builder 看那位大大能翻成Delphi,例子中是存於Image中:
  Graphics::TBitmap *newBitmap;
  newBitmap = new Graphics::TBitmap();
  HDC ScreenDC;
  TPoint REOrg;
  try  {
    Image1->Picture->Graphic=newBitmap;
    Image1->Picture->Graphic->Width=RichEdit1->ClientWidth;
    Image1->Picture->Graphic->Height=RichEdit1->ClientHeight;
    REOrg=RichEdit1->ClientToScreen(Point(0,0));
    ScreenDC=GetDC(0);
    try    {
      BitBlt(Image1->Picture->Bitmap->Canvas->Handle,0,0,RichEdit1->ClientWidth,RichEdit1->ClientHeight,ScreenDC,REOrg.x, REOrg.y, SRCCOPY);
    }
    __finally    {
      ReleaseDC(0, ScreenDC);
    }
  }
  __finally  {
    newBitmap->Free();
  }    
Andy Chang
------
Andy Chang
SCBT
一般會員


發表:2
回覆:3
積分:1
註冊:2004-02-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-19 02:13:28 IP:220.130.xxx.xxx 未訂閱
小弟我太肉腳了剛學Delphi,又是自學的對於下面的程式中的 procedure RTFtoBitmap(cFileName: string; AParentWin: HWND; nWidth, nHeight:integer; var bm: TBitmap); 這個procedure RTFtoBitmap不知道怎麼使用,例如裡面的AParentWin: HWND跟 var bm: TBitmap要傳入甚麼值! 請高手能指導我一下,謝謝!! ---------------------------------------------------------------- uses ... , RichEdit; function PixelsToTwipsH(hDC: THandle; nPixels: integer): integer; var nPixelsPerInch: double; begin nPixelsPerInch := GetDeviceCaps(hDC, LOGPIXELSX); Result := Round((1440 / nPixelsPerInch) * nPixels); end; function PixelsToTwipsV(hDC: THandle; nPixels: integer): integer; var nPixelsPerInch: double; begin nPixelsPerInch := GetDeviceCaps(hDC, LOGPIXELSY); Result := Round((1440 / nPixelsPerInch) * nPixels); end; // load a rich text file into a bitmap of desired width and height procedure RTFtoBitmap(cFileName: string; AParentWin: HWND; nWidth, nHeight: integer; var bm: TBitmap); var fmtRange: TFormatRange; red: TRichEdit; begin if not Assigned(bm) then bm := TBitmap.Create; try bm.Width := nWidth; bm.Height := nHeight; red := TRichEdit.CreateParented(AParentWin); // gotta have a parent try red.Lines.LoadFromFile(cFileName); fmtRange.hdc := bm.Canvas.Handle; fmtRange.hdcTarget := bm.Canvas.Handle; fmtRange.rc := Rect(0, 0, PixelsToTwipsH(fmtRange.hdc, nWidth), PixelsToTwipsV(fmtRange.hdc, nHeight)); fmtRange.rcPage := fmtRange.rc; fmtRange.chrg.cpMin := 0; fmtRange.chrg.cpMax := -1; with red do begin Perform(EM_FORMATRANGE, Integer(true), Integer(@fmtRange)); Perform(EM_FORMATRANGE, Integer(true), 0); end; finally red.Free; end; except end; // error handling here end;
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-19 08:39:23 IP:202.39.xxx.xxx 未訂閱
試試用法如下:
procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
begin
  RtfToBitmap('c:\xx.bmp', Form1.Handle, 800, 600, bmp);
end;
-- 歡迎光臨 KTop 研究苑!
SCBT
一般會員


發表:2
回覆:3
積分:1
註冊:2004-02-05

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-08-20 00:26:57 IP:220.130.xxx.xxx 未訂閱
感謝指導! 使用 RtfToBitmap('C:\aa.RTF', Form1.Handle, 800, 600, Bitmap); 之後已經成功! 不過成果不如預期,因為原RTF檔編輯格式已經跑掉。 看起來只有文字一行一行的。 不過還是很感謝,因為也學了不少 謝謝~
adonis
高階會員


發表:140
回覆:258
積分:159
註冊:2002-04-15

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-04-14 14:41:45 IP:210.201.xxx.xxx 未訂閱
hagar 您好 看到這則討論讓我獲益不少。有幾個問題想請教各位前輩 ~ 1. 我利用http://groups.google.com/groups?hl=zh-TW&lr=&ie=UTF-8&th=9e1bebdae16cd3d8&rnum=3所提及的方式發現當RTF中為不只一頁的內容時,但總是顯示第一頁,不知多頁時該如何處理? 2. 若RTF文件中若有圖形則無法顯示出來,其餘正常,不知該如何處理? 謝謝。
------
我也在努力學習中,若有錯謬請見諒。
系統時間:2024-05-18 5:35:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!