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

Graphics::TBitmap的問題

答題得分者是:taishyang
ceenim78
一般會員


發表:2
回覆:2
積分:0
註冊:2008-03-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-12-11 02:13:12 IP:218.165.xxx.xxx 訂閱
以下是我的程式碼
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br />#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMainMenu *MainMenu1;
TImage *Image1;
TMenuItem *Items5;
void __fastcall Items5Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private:
// User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif



Unit1.cpp
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
BITMAP bm;
Graphics::TBitmap *Bitmap1;
int i,j;
int WideHalf;
TRect Dest1,Source1,Dest2,Source2;
int HeightHalf;
HRGN MyRgn;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Items5Click(TObject *Sender)
{
Form1->Refresh( );
for(i=Bitmap1->Width;i>=0;i--) <-------------------進行編譯此行一開始就會產生問題
{
Dest1=Rect(0,0,Bitmap1->Width-i,Bitmap1->Height);
Source1=Rect(i,0,Bitmap1->Width,Bitmap1->Height);
Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
for(j=0;j<10000;j );
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();
Bitmap1->LoadFromFile("C:\\factory.bmp");
if(GetDeviceCaps(Form1->Canvas->Handle,BITSPIXEL)==8)//取得顯示窗口的顏色屬性//
{
GetObject(Bitmap1->Handle,sizeof(BITMAP),(LPSTR)&bm);
if (bm.bmBitsPixel==8)//如果特效顯示的圖象顏色屬性為256色//
{
SelectPalette(Form1->Canvas->Handle,Bitmap1->Palette,FALSE);//從特效顯示的顏色畫板中提取配色方案//
RealizePalette(Form1->Canvas->Handle); //在顯示窗口中設置配色方案//
}
Bitmap->HandleType=bmDDB;
}

}
//---------------------------------------------------------------------------

我是參照這篇文章去做,但是就是一直無法編譯成功,可以請問一下為什麼會這樣呢?
http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=20229
附加檔案:494006b88ca55_dos.rar
編輯記錄
ceenim78 重新編輯於 2008-12-11 11:32:23, 註解 無‧
ceenim78 重新編輯於 2008-12-11 11:56:33, 註解 無‧
taishyang
站務副站長


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-12-11 10:30:25 IP:118.169.xxx.xxx 訂閱
因為你是直接複製貼上別人的程式碼
解決的方式就是把每一行前面的空白去掉,重新排版,或是copy下面的code

void __fastcall TForm1::Items5Click(TObject *Sender)
{
Form1->Refresh();
for(i=Bitmap1->Width; i >= 0; i--){
Dest1=Rect(0,0,Bitmap1->Width-i,Bitmap1->Height);
Source1=Rect(i,0,Bitmap1->Width,Bitmap1->Height);
Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
for(j=0; j<10000; j );
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap(); //定義一個圖象句柄//
Bitmap1->LoadFromFile("C:\\factory.bmp"); //設定所要特效顯示的圖象為factory.bmp//
if(GetDeviceCaps(Form1->Canvas->Handle,BITSPIXEL)==8){ //取得顯示窗口的顏色屬性//
GetObject(Bitmap1->Handle,sizeof(BITMAP),(LPSTR)&bm);
if (bm.bmBitsPixel==8){ //如果特效顯示的圖象顏色屬性為256色//
SelectPalette(Form1->Canvas->Handle,Bitmap1->Palette,FALSE);//從特效顯示的顏色畫板中提取配色方案//
RealizePalette(Form1->Canvas->Handle); //在顯示窗口中設置配色方案//
}
Bitmap1->HandleType=bmDDB;
}
}
//---------------------------------------------------------------------------
編輯記錄
taishyang 重新編輯於 2008-12-11 10:34:32, 註解 無‧
taishyang 重新編輯於 2008-12-11 10:35:13, 註解 無‧
ceenim78
一般會員


發表:2
回覆:2
積分:0
註冊:2008-03-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-12-11 11:38:39 IP:218.165.xxx.xxx 訂閱
感謝解答!!  
那請問一下為何bcb會有這種空格的錯誤?
雖然程式編譯無錯...但是現再又遇到另一個問題
Form1->Refresh();
for(i=Bitmap1->Width; i >= 0; i--){ <-------------------------------這一行會產生錯誤
Dest1=Rect(0,0,Bitmap1->Width-i,Bitmap1->Height);
Source1=Rect(i,0,Bitmap1->Width,Bitmap1->Height);
Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
for(j=0; j<10000; j );
}



我已經把整個程式碼加上圖片重新上傳包括產生出來的錯誤訊息的圖片...
編輯記錄
ceenim78 重新編輯於 2008-12-11 11:53:00, 註解 無‧
ceenim78 重新編輯於 2008-12-11 11:58:59, 註解 無‧
taishyang
站務副站長


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-12-11 11:56:46 IP:118.169.xxx.xxx 訂閱
記憶體違規存取的問題,自己比對一下哪裡不一樣

void __fastcall TForm1::Items5Click(TObject *Sender)
{
Form1->Refresh();
for(i=Bitmap1->Width; i >= 0; i--){
Dest1=Rect(0,0,Bitmap1->Width-i,Bitmap1->Height);
Source1=Rect(i,0,Bitmap1->Width,Bitmap1->Height);
Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);
for(j=0; j<10000; j );
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Bitmap1 = new Graphics::TBitmap(); //定義一個圖象句柄//
Bitmap1->LoadFromFile("C:\\test.bmp"); //設定所要特效顯示的圖象為factory.bmp//
if(GetDeviceCaps(Form1->Canvas->Handle,BITSPIXEL)==8){ //取得顯示窗口的顏色屬性//
GetObject(Bitmap1->Handle,sizeof(BITMAP),(LPSTR)&bm);
if (bm.bmBitsPixel==8){ //如果特效顯示的圖象顏色屬性為256色//
SelectPalette(Form1->Canvas->Handle,Bitmap1->Palette,FALSE);//從特效顯示的顏色畫板中提取配色方案//
RealizePalette(Form1->Canvas->Handle); //在顯示窗口中設置配色方案//
}
Bitmap1->HandleType=bmDDB;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete Bitmap1;
}
//---------------------------------------------------------------------------
編輯記錄
taishyang 重新編輯於 2008-12-11 11:57:27, 註解 無‧
ceenim78
一般會員


發表:2
回覆:2
積分:0
註冊:2008-03-04

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-12-11 12:06:26 IP:218.165.xxx.xxx 訂閱
非常感謝...問題已經解決了!!!!  謝謝~~~~

後來知道原來我這裡多打了Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();
應該寫成Bitmap1 = new Graphics::TBitmap();

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