limeca你好:
我已經可以run了...但是我有個地方不懂..就是位什麼我連點都還沒點就會在listbox裡面跑出所有的數值呢?
我給您看一下我加後的程式碼
#include
#pragma hdrstop
#include
#include "Unit1.h"
#include
int number=0;
int x_buffer[255];
int y_buffer[255];
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Graphics::TBitmap *TheBitmap;
TheBitmap=Image1->Picture->Bitmap; char buf[64];
sprintf(buf,"%d\t%d",X,Y);
ListBox1->Items->Add(buf);
x_buffer[number]=X;
y_buffer[number]=Y;
number ; if(TheBitmap->ScanLine[0])
{
StatusBar1->Panels->Items[0]->Text="X座標=>" IntToStr(X);
StatusBar1->Panels->Items[1]->Text="Y坐標=>" IntToStr(Y);
} if(Masking)
{
TheBitmap->Canvas->Pen->Style=psDash;
TheBitmap->Canvas->Pen->Mode=pmBlack;
TheBitmap->Canvas->Brush->Style=bsClear; TheBitmap->Canvas->Draw(0,0,OrgBitmap);
TheBitmap->Canvas->Rectangle(StartX,StartY,X,Y); }
if(Pasting)
{
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
TheBitmap->Canvas->Pen->Style=psDash;
TheBitmap->Canvas->Pen->Mode=pmBlack;
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Rectangle(X-StartX,Y-StartY,X-StartX PasteBitmap->Width,
Y-StartY PasteBitmap->Height); } }
//--------------------------------------------------------------------------- void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
float ScaleFactor; if(ComboBox1->Text=="25%")
ScaleFactor=4.0;
else if(ComboBox1->Text=="50%")
ScaleFactor=2.0;
else if(ComboBox1->Text=="75%")
ScaleFactor=1.25;
else if(ComboBox1->Text=="100%")
ScaleFactor=1.0;
else if(ComboBox1->Text=="150%")
ScaleFactor=0.75;
else if(ComboBox1->Text=="200%")
ScaleFactor=0.5;
else
{
ScaleFactor=1.0;
ComboBox1->Text="100%";
} Image1->AutoSize=false;
Image1->Stretch=true;
Image1->Width=Image1->Picture->Bitmap->Width/ScaleFactor;
Image1->Height=Image1->Picture->Bitmap->Height/ScaleFactor; }
//--------------------------------------------------------------------------- void __fastcall TForm1::N12Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap, *TempBitmap;
int Width,Height;
Byte *ptr1,*ptr2; TempBitmap= new Graphics::TBitmap(); TheBitmap= Image1->Picture->Bitmap;
TheBitmap->PixelFormat=pf8bit; TempBitmap->Assign(TheBitmap); Width=TheBitmap->Width;
Height=TheBitmap->Height; for(int y=0;yScanLine[y];
ptr2=(Byte*)TheBitmap->ScanLine[y]; for(int x=0;xAssign(TempBitmap);
delete TempBitmap;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::N13Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap, *TempBitmap;
int Width,Height;
Byte *ptr1,*ptr2; TempBitmap= new Graphics::TBitmap(); TheBitmap= Image1->Picture->Bitmap; TempBitmap->Assign(TheBitmap); Width=TheBitmap->Width;
Height=TheBitmap->Height; for(int y=0;yCanvas->Pixels[x][y]=
TheBitmap->Canvas->Pixels[x][Height-1-y]; TheBitmap->Assign(TempBitmap);
delete TempBitmap;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::N15Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap, *TempBitmap;
int Width,Height;
Byte *ptr1,*ptr2; TempBitmap= new Graphics :: TBitmap(); TheBitmap=Image1->Picture->Bitmap;
TheBitmap->PixelFormat=pf8bit; Width=TheBitmap->Width;
Height=TheBitmap->Height; TempBitmap->Assign(TheBitmap); TempBitmap->Width=Height;
TempBitmap->Height=Width; for(int y=0;yScanLine[y];
for(int x=0;xScanLine[Width-1-x];
ptr1[y]=ptr2[x];
} } TheBitmap->Assign(TempBitmap);
delete TempBitmap;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::N16Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap, *TempBitmap;
int Width,Height;
Byte *ptr1,*ptr2; TempBitmap= new Graphics :: TBitmap(); TheBitmap=Image1->Picture->Bitmap;
TheBitmap->PixelFormat=pf8bit; Width=TheBitmap->Width;
Height=TheBitmap->Height; TempBitmap->Assign(TheBitmap); TempBitmap->Width=Height;
TempBitmap->Height=Width; for(int y=0;yScanLine[y];
for(int x=0;xScanLine[x];
ptr1[Height-1-y]=ptr2[x];
} } TheBitmap->Assign(TempBitmap);
delete TempBitmap; }
//--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Graphics::TBitmap *TheBitmap; StartX=X;
StartY=Y; if(Pasting_Enable)
{
Pasting=true; Masking=false;
Pasting_Enable=false;
}
else
{
Masking=true; Pasting=false;
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
} Masking=true; TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Graphics::TBitmap *TheBitmap; if(Pasting)
{
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
OrgBitmap->Assign(TheBitmap);
Pasting=false;
} Masking=false; EndX=X;
EndY=Y;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::N6Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
int Width,Height;
int TFX,TFY,BRX,BRY;
TRect SrcRect,DestRect; TheBitmap=Image1->Picture->Bitmap; TheBitmap->Canvas->Draw(0,0,OrgBitmap); TempBitmap= new Graphics::TBitmap(); Width=abs(EndX-StartX);
Height=abs(EndY-StartY); TFX= min(EndX,StartX); BRX= max(EndX,StartX);
TFY= min(EndY,StartY); BRY= max(EndY,StartY); TempBitmap->Width=Width;
TempBitmap->Height=Height;
TempBitmap->PixelFormat=pf24bit;
TempBitmap->Canvas->CopyMode=cmSrcCopy;
SrcRect=Rect(TFX,TFY,BRX,BRY);
DestRect=Rect(0,0,Width,Height);
TempBitmap->Canvas->CopyRect(DestRect,TheBitmap->Canvas,SrcRect); Clipboard()->Assign(TempBitmap); TheBitmap->Canvas->Pen->Style=psSolid;
TheBitmap->Canvas->Pen->Mode=pmWhite;
TheBitmap->Canvas->Brush->Style=bsSolid;
TheBitmap->Canvas->Brush->Color=clWhite;
TheBitmap->Canvas->Rectangle(TFX,TFY,BRX,BRY); OrgBitmap->Assign(TheBitmap); }
//--------------------------------------------------------------------------- void __fastcall TForm1::N7Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap,*TempBitmap;
int Width,Height;
int TFX,TFY,BRX,BRY;
TRect SrcRect,DestRect; TheBitmap=Image1->Picture->Bitmap; TheBitmap->Canvas->Draw(0,0,OrgBitmap); TempBitmap=new Graphics::TBitmap(); Width=abs(EndX-StartX);
Height=abs(EndY-StartY); TFX=min(EndX,StartX); BRX=max(EndX,StartX);
TFY=min(EndY,StartY); BRY=max(EndY,StartY); TempBitmap->Width=Width;
TempBitmap->Height=Height;
TempBitmap->PixelFormat=pf24bit;
TempBitmap->Canvas->CopyMode=cmSrcCopy;
SrcRect=Rect(TFX,TFY,BRX,BRY);
DestRect=Rect(0,0,Width,Height); TempBitmap->Canvas->CopyRect(DestRect,TheBitmap->Canvas,SrcRect); Clipboard()->Assign(TempBitmap);
}
//--------------------------------------------------------------------------- void __fastcall TForm1::N8Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap; TheBitmap=Image1->Picture->Bitmap; if(Clipboard()->HasFormat(CF_BITMAP))
{
PasteBitmap->Assign(Clipboard()); TheBitmap->Canvas->Draw(0,0,PasteBitmap); TheBitmap->Canvas->Pen->Width=2;
TheBitmap->Canvas->Pen->Mode=pmBlack;
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Rectangle(0,0,PasteBitmap->Width,PasteBitmap->Height);
Pasting_Enable=true;
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *TheBitmap;
Byte *ptr;
int r,g,b;
int gray;
int i,j;
TheBitmap = Image1->Picture->Bitmap;
for (j=0; jHeight; j )
{
ptr = (Byte *)TheBitmap->ScanLine[j];
for (i=0; iWidth; i )
{
b = ptr[i*3];
g = ptr[i*3 1];
r = ptr[i*3 2];
gray = 0.299*r 0.587*g 0.114*b;
if (gray>125)
gray = 255;
else
gray = 0;
ptr[i*3 ] = (Byte)gray;
ptr[i*3 1] = (Byte)gray;
ptr[i*3 2] = (Byte)gray;
}
}
Image1->Picture->Assign(TheBitmap);
}