之前曾經介紹過如何 動態宣告二維陣列, 可是彩色影像是由 RGB 三個色彩所組成, 如果想用一個三維陣列來儲存一張彩色影像的 RGB 色彩值, 那又要該如何修改程式呢?
// 標頭檔
#include <iostream.h>
// 宣告
int ***iComponent;
// 程式
try
{
iComponent = new int **[3];
for (i=0;i<3;i++)
{
iComponent[i] = new int *[20];
for (j=0;j<20;j++)
iComponent[i][j] = new int [40];
}
}
catch (std::bad_alloc)
{
ShowMessage("Could not allocate memory...Bye");
exit(-1);
}
// 使用測試
iComponent[2][19][39]= 10;
ShowMessage(AnsiString(iComponent[2][19][39]));
注意: 上述程式為了程式的可讀性, 用了全型的空白" "來控制部落格文章的內縮顯示。因此, 如果你要直接複製上述程式到 C++ Builder 執行, 請務必將全型空白" "改成半型空白" ", 否則, 編譯時發出現以下的錯誤訊息。:
[C++ Error] Unit1.cpp(40): E2206 Illegal character ' ' (0xa140)
Showing posts with label image. Show all posts
Showing posts with label image. Show all posts
Wednesday, November 09, 2011
Friday, September 09, 2011
Image Properties
Wednesday, September 07, 2011
TCanvas::FillRect Method
Image1->Canvas->Brush->Color = (TColor) RGB(130,67,33);
Image1->Canvas->FillRect(Rect(50,100,80,200));
這兩行指令就是
1. 設定Image1畫布上筆刷的顏色為 (130,67,33)
2. 把矩形 Rect(50,100,80,200) 用筆刷填滿
Image1->Canvas->FillRect(Rect(50,100,80,200));
這兩行指令就是
1. 設定Image1畫布上筆刷的顏色為 (130,67,33)
2. 把矩形 Rect(50,100,80,200) 用筆刷填滿
Thursday, December 20, 2007
如何動態新增一個影像元件?
TImage *imNew;
imNew = new TImage(this);
imNew->Parent = RScrollBox;
imNew->Left = 2;
imNew->Top = 2;
imNew->Height = IH;
imNew->Width = IW;
上述這段程式, 如果執行時出現下面的錯誤訊息:
[Linker Error] Unresolved external '__fastcall Extctrls::TImage::TImage(Classes::TComponent *)' referenced from...
解決辦法:
'Project | Options | (tab) Packages | (Groupbox) Runtime Packages',
將 Build with Runtime Packages 的勾勾去掉...
imNew = new TImage(this);
imNew->Parent = RScrollBox;
imNew->Left = 2;
imNew->Top = 2;
imNew->Height = IH;
imNew->Width = IW;
上述這段程式, 如果執行時出現下面的錯誤訊息:
[Linker Error] Unresolved external '__fastcall Extctrls::TImage::TImage(Classes::TComponent *)' referenced from...
解決辦法:
'Project | Options | (tab) Packages | (Groupbox) Runtime Packages',
將 Build with Runtime Packages 的勾勾去掉...
Saturday, October 21, 2006
TCanvas::CopyRect method
Copies part of an image from another canvas into the canvas.
void __fastcall CopyRect(const TRect &Dest, TCanvas* Canvas, const TRect &Source);TCanvas::CopyRect method 可以將另外一個 Canvas ( 第二個輸入參數 ) 中的特定長方塊 (rectangle) ( 第三個輸入參數 ) 中的影像 copy 到自己這個 Canvas 的特定長方塊( 第一個輸入參數 ) 中。
Description
Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object. Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image. Source specifies a rectangle bounding the portion of the source canvas that will be copied.
The portion of the source canvas is copied using the mode specified by CopyMode.
Monday, September 11, 2006
開啟 JPEG 影像
BCB Professional 版本並不提供直接開啟 JPEG 影像的功能, 要開啟 JPEG 影像, 要自己寫 JPEG 的 decoder, 這個有點難度, 不然就是直接上網找別人寫的程式, 弄懂後, 想辦法和自己的程式結合起來。不過, 如果是 BCB Enterprise 版本, 要開啟 JPEG 影像就容易多了, 只要在程式最前面宣告的部份, 加入:
#include "jpeg.hpp"
至於其他的步驟, 則都和 開啟 BMP 影像 相同。
如果你想要看看 jpeg.hpp 這個檔案的內容, 你可以在
C:\Program Files\Borland\CBuilder6\Include\Vcl\
這個目錄中找到這個檔案。如果你沒有安裝 BCB Enterprise 版, 你可以按這邊 一賭為快。
#include "jpeg.hpp"
至於其他的步驟, 則都和 開啟 BMP 影像 相同。
如果你想要看看 jpeg.hpp 這個檔案的內容, 你可以在
C:\Program Files\Borland\CBuilder6\Include\Vcl\
這個目錄中找到這個檔案。如果你沒有安裝 BCB Enterprise 版, 你可以按這邊 一賭為快。
開啟與儲存 BMP 影像
在 BCB 中, 要寫程式開啟一張 BMP 影像, 非常的簡單, 主要步驟有二:
1. 利用 OpenPictureDialog1->Execute() 來選定你所希望開啟的影像。
OpenPictureDialog 這個對話方塊專門設計用來開啟一張影像的, Execute() 這個method 並不需要任何的傳入值, 當我們用對話視窗選定一個影像檔後, 則會傳回一個 boolean 值 ( true or false), 來表示是否執行成功。如果傳回值是 true, Execute() 就會把你所選擇的檔案名稱 (包刮路徑), 存在FileName 這個字串中。
2. 再利用 Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName)
將影像顯示到 Image1 這個影像物件中。
LoadFromFile 這個 method 的輸入值就是你要開啟的路徑與檔案名稱。
同樣地, 要將影像物件的內容儲存成 BMP 影像檔案, 也是有兩個步驟:
1. 利用 SavePictureDialog1->Execute() 來選定你所希望開啟的影像。
2. 利用 Image1->Picture->SaveToFile(SavePictureDialog1->FileName)
將影像內容儲存成檔名為 SavePictureDialog1->FileName 的 BMP 檔案中。
1. 利用 OpenPictureDialog1->Execute() 來選定你所希望開啟的影像。
OpenPictureDialog 這個對話方塊專門設計用來開啟一張影像的, Execute() 這個method 並不需要任何的傳入值, 當我們用對話視窗選定一個影像檔後, 則會傳回一個 boolean 值 ( true or false), 來表示是否執行成功。如果傳回值是 true, Execute() 就會把你所選擇的檔案名稱 (包刮路徑), 存在FileName 這個字串中。
2. 再利用 Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName)
將影像顯示到 Image1 這個影像物件中。
LoadFromFile 這個 method 的輸入值就是你要開啟的路徑與檔案名稱。
同樣地, 要將影像物件的內容儲存成 BMP 影像檔案, 也是有兩個步驟:
1. 利用 SavePictureDialog1->Execute() 來選定你所希望開啟的影像。
2. 利用 Image1->Picture->SaveToFile(SavePictureDialog1->FileName)
將影像內容儲存成檔名為 SavePictureDialog1->FileName 的 BMP 檔案中。
Subscribe to:
Posts (Atom)