全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2645
推到 Plurk!
推到 Facebook!

請教有關TGraphic與Panel上繪圖的問題

尚未結案
danielj
初階會員


發表:65
回覆:135
積分:40
註冊:2003-06-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-15 09:52:13 IP:61.220.xxx.xxx 未訂閱
小弟現在已知圖片的rgb內容(共寬X高X3bytes),我想利用較快速的方法將此圖片內容秀在Panel上,因此我現在遇到了以下的問題: 1. 我記得如果是要在Canvas上的某座標直接繪圖的畫,可能要將rgb內容轉為TGraphic型態,那我該怎麼轉呢? 2. TPanel並無Canvas元件,是否可利用http://delphi.ktop.com.tw/topic.php?TOPIC_ID=35587的方法產生Canvas並在其上繪圖呢?還是得在Panel上放Image元件才行得通?
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-15 13:44:00 IP:140.135.xxx.xxx 未訂閱
danielj您好: 1.
((TPanelCanvas*)Panel1)->Canvas->Pixels[120][150]=TColor(RGB(255,255,255)); 
2. 要快的話,個人覺得第二項比較好(速度考量),因為Bitmap有ScanLine[] 可以使處理速度變的相當快 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-15 14:11:27 IP:61.218.xxx.xxx 未訂閱
danielj您好:      這有個TImagePanel的元件,您可以參看看他的寫法,或者直接使用這個元件:    官方網站:http://www.leunen.com/
官方下載:http://www.leunen.com/download/imgpanel.zip
本地下載:http://delphi.ktop.com.tw/loadfile.php?TOPICID=11201344&CC=250516    /*---------------------------------------------------------------------------
Program :                  ImagePanel.cpp        Version 1.1
                                            TImagePanel Component for BCB1 and BCB3/4/5
Author :                  Michel Leunen
Email :                          leu@rtbf.be
                                            Michel@leunen.com
Date :                          04/08/1998
Description :        Component for Borland C++ Builder V1 that draws a bitmap on a
                                            TPanel. The image could be stretchd, tiled or drawn alone.
*/
//---------------------------------------------------------------------------
#include 
#include 
#pragma hdrstop    #include "ImagePanel.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
static inline void ValidCtrCheck(TImagePanel *)
{
        new TImagePanel(NULL);
}
//---------------------------------------------------------------------------
__fastcall TImagePanel::TImagePanel(TComponent* Owner)
        : TGraphicControl(Owner)
{
  FBitmap=new Graphics::TBitmap();
        FImageStyle=ipSingle;
  FXPosition=0;
  FYPosition=0;
        Width=100;
        Height=36;
  Caption="";
}
//---------------------------------------------------------------------------
 __fastcall TImagePanel::~TImagePanel()
{
         delete FBitmap;
  FBitmap=NULL;
}
//---------------------------------------------------------------------------
namespace Imagepanel
{
        void __fastcall PACKAGE Register()
        {
                TComponentClass classes[1] = {__classid(TImagePanel)};
                RegisterComponents("Leunen", classes, 0);
        }
}
//---------------------------------------------------------------------------
void __fastcall TImagePanel::Paint(void)
{
  //Paint Rect around control
  Canvas->Pen->Style=psSolid;
  Canvas->Pen->Color=clBlack;
  Canvas->LineTo(Width-1,0);
  Canvas->Pen->Color=clWhite;
  Canvas->LineTo(Width-1,Height-1);
  Canvas->LineTo(0,Height-1);
  Canvas->Pen->Color=clBlack;
  Canvas->LineTo(0,0);      if(ValidBmp && FBitmap->Modified)
  {
    tmpBitmap=new Graphics::TBitmap();
    tmpBitmap->Assign(FBitmap);
    if(FBitmap)
    {
      int i,j,bmpWidth,bmpHeight;
      TRect        rect;
      rect=ClientRect;
      rect.Top++;
      rect.Right--;
      rect.Bottom--;
      rect.Left++;
      switch ((int)FImageStyle)
      {
        case ipSingle:
          if(tmpBitmap->Width>rect.Right-FXPosition)
              bmpWidth=rect.Right-FXPosition;
          else bmpWidth=tmpBitmap->Width;
          if(tmpBitmap->Height>rect.Bottom-FYPosition)
              bmpHeight=rect.Bottom-FYPosition;
          else bmpHeight=tmpBitmap->Height;
            ::BitBlt(Canvas->Handle,
                     FXPosition,
                     FYPosition,
                     bmpWidth,
                     bmpHeight,
                     tmpBitmap->Canvas->Handle,
                     0,
                     0,
                     SRCCOPY);
          break;            case ipStretch:
          Canvas->StretchDraw(rect,tmpBitmap);
          break;            case ipTile:
          for(i=rect.Top;iHeight)
          {
            for(j=rect.Left;jWidth)
            {
              if(jWidth)bmpWidth=tmpBitmap->Width;
              else bmpWidth=rect.Right-j;
              if(iHeight)bmpHeight=tmpBitmap->Height;
              else bmpHeight=rect.Bottom-i;
              ::BitBlt(Canvas->Handle,
                        j,
                        i,
                        bmpWidth,
                        bmpHeight,
                        tmpBitmap->Canvas->Handle,
                        0,
                        0,
                        SRCCOPY);
              }
            }
      }
    }
    delete tmpBitmap;
  }
}
//---------------------------------------------------------------------------
void __fastcall TImagePanel::SetBitmap(Graphics::TBitmap *ABitmap)
{
  if (ABitmap!=NULL)ValidBmp=true;
  else ValidBmp=false;
        FBitmap->Assign(ABitmap);
  Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TImagePanel::SetXPos(int AXPosition)
{
        FXPosition=AXPosition;
  Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TImagePanel::SetYPos(int AYPosition)
{
        FYPosition=AYPosition;
  Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TImagePanel::SetImageStyle(TImageDrawStyle AImageStyle)
{
        FImageStyle=AImageStyle;
  Repaint();
}
//---------------------------------------------------------------------------    /*---------------------------------------------------------------------------
Program :                  ImagePanel.cpp        Version 1.1
                                            TImagePanel Component for BCB1 and BCB3/4/5
Author :                  Michel Leunen
Email :                          leu@rtbf.be
                                            Michel@leunen.com
Date :                          04/08/1998
Description :        Component for Borland C++ Builder V1 that draws a bitmap on a
                                            TPanel. The image could be stretchd, tiled or drawn alone.
*/
//---------------------------------------------------------------------------
#ifndef ImagePanelH
#define ImagePanelH
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include 
#include 
#include 
//---------------------------------------------------------------------------
enum  TImageDrawStyle {ipSingle,ipStretch,ipTile};                //Enum drawing Style
class PACKAGE TImagePanel : public TGraphicControl
{
private:
        Graphics::TBitmap                *FBitmap,*tmpBitmap;
  int FXPosition;                                     //x origin
  int        FYPosition;                                                                                // y origin
        bool ValidBmp;
  TImageDrawStyle                FImageStyle;                      // drawing style
  void __fastcall SetBitmap(Graphics::TBitmap *ABitmap);
  void __fastcall SetImageStyle(TImageDrawStyle AImageStyle);
  void __fastcall SetXPos(int AXPosition);
  void __fastcall SetYPos(int AYPosition);    protected:
        void __fastcall Paint(void);                                                                         // override paint()    public:
        __fastcall TImagePanel(TComponent* Owner);
  __fastcall ~TImagePanel();    __published:
        __property Graphics::TBitmap *Bitmap = {read=FBitmap, write=SetBitmap};
  __property TImageDrawStyle DrawingStyle = {read=FImageStyle, write=SetImageStyle};
  __property int XPosition = {read=FXPosition, write=SetXPos};
  __property int YPosition = {read=FYPosition, write=SetYPos};
        __property Align;
  __property ShowHint;
  __property ParentShowHint;
  __property Canvas;
  __property Visible;
  __property OnClick;
  __property OnMouseMove;
  __property OnMouseDown;
  __property OnMouseUp;    };
//---------------------------------------------------------------------------
#endif
HAVE A NICE DAY FOR YOU
danielj
初階會員


發表:65
回覆:135
積分:40
註冊:2003-06-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-08-19 09:48:34 IP:61.220.xxx.xxx 未訂閱
多謝taishyang以及axsoft的回答! 能否再詳細請教一下taishyang: 您覺得第二種方式較快,是指在Panel上放image嗎?因為Canvas上並沒有Bitmap可用啊?還是小弟太笨那裡弄錯了? 麻煩taishyang或者是知道詳情的高手們幫忙回答一下… 再次感謝大家…
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-08-21 14:37:14 IP:140.135.xxx.xxx 未訂閱
danielj您好:
引言: 能否再詳細請教一下taishyang: 您覺得第二種方式較快,是指在Panel上放image嗎?因為Canvas上並沒有Bitmap可用啊?
我指的就是您所說的Panel上放image < class="code"> Image1->Picture->Bitmap->ScanLine... 有了ScanLine相信速度會快很多 順心 <>~我也是在學習的階段,回答的不好請您多多見諒與指教~
danielj
初階會員


發表:65
回覆:135
積分:40
註冊:2003-06-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-08-21 17:32:00 IP:61.220.xxx.xxx 未訂閱
再次謝謝taishyang! 所以在Panel上放Image應該是目前得到最佳的方法… 但是我還是有疑問:ScanLine不就只是取出各Line的開始位置而已嗎?其它的還是一個畫素一個畫素的給值啊,為什麼就是會快很多?
系統時間:2024-04-29 23:12:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!