⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.~cpp

📁 05年毕业设计(BC)-图像处理软件及完整源代码
💻 ~CPP
📖 第 1 页 / 共 4 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit13.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//TForm2 *Form2;
extern int iFormNum;             //子窗数
extern int iActForm2;               //当前活动子窗口
extern int iGraphStyle;           //图形的样式
extern int iGraphThick;           //图形的粗细
extern bool bIsTransparence;       //是否透明
extern TColor tBrushColor;         //填充颜色
extern TColor tGroundColor;       //背景色
extern TColor tGraphColor;          //图形颜色
extern bool bForm2Null[50];
extern int iForm2Sum;
extern int iTemplate[4][4];         //平滑操作参数 模板
extern int iTNum;                   //平滑操作参数 模板维度
extern TPoint pProcessBegin,pProcessEnd;  //处理图像的开始点和终止点的坐标
extern int iThre;                //锐化参数  阈值   在二值化中也有用到
extern long lCopyStyle;      //合并参数

long lXTemp,lYTemp;
int iR,iG,iB;
TColor tTempColor;
float fWtempR,fWtempG,fWtempB;     //点运算变量
float fla;
int ilb;
int iSmoothStyle;   //因为拉普拉斯锐化也是模板操作,所以和平滑共用一个函数  浮雕效果   柔化模板操作
Graphics::TBitmap *bBitmapCopy=new Graphics::TBitmap;

TCursor tCurTemp;  //光标临时变量
long lProStep,lProSum,lProi;     //设置进度条变量
int iSunDirection=1;           //浮雕效果中的光方向
int iSunConstant=128;               //浮雕平面的灰度

int iSpreadBound=5;                //扩散处理的范围
long lofx,lofy,lforx,lfory;
int iTemp,jTemp;

int iPointRange;         //点运算范围
extern int iMASAIKE;         //马赛克颗粒大小
TPoint preP,curP;       //画图形时的坐标
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
        : TForm(Owner)
{
        int i;
        iPicNum=10;             //设置缓冲图像区的数量
        iPicBegin=1;
        iPicEnd=0;   //初始化画板的
        iPicNow=0;
        iMaxZoom=4;
        iZoom=0;
        pPBegin.x=0;
        pPBegin.y=0;
        pPEnd.x=lPicWidth;
        pPEnd.y=lPicHeight;
        sOperator[0]="打开";
        iPointRange=0;
        for(i=0;i<iPicNum;i++)
                bPicArray[i]=new Graphics::TBitmap();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormResize(TObject *Sender)
{
        if(Panel1->Width < this->ClientWidth)
                Panel1->Left=(this->ClientWidth - Panel1->Width)/2;
        else
                Panel1->Left=0;
        if(Panel1->Height < this->ClientHeight)
                Panel1->Top=(this->ClientHeight - Panel1->Height)/2;
        else
                Panel1->Top=0;

}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
        int i;
        i=MessageBox(NULL,"是否保存图像","Question?",MB_YESNOCANCEL|MB_ICONQUESTION);
        if(i==IDYES)
        {
                //保存
        gotosave:
                if(SaveDialog1->Execute())
                {
                        if(FileExists(SaveDialog1->FileName))
                        {
                                i=MessageBox(NULL,"您所指定的文件已经存在,是否覆盖?","Question",MB_YESNOCANCEL|MB_ICONQUESTION);
                                if(i==IDNO)
                                        goto gotosave;
                                if(i==IDYES)
                                {
                                        if(!DeleteFile(SaveDialog1->FileName))
                                        {
                                                MessageBox(NULL,"指定的文件正在使用,无法覆盖","error",MB_OK|MB_ICONERROR);
                                                goto gotosave;
                                        }
                                }
                                else
                                {
                                        Action=caNone;
                                        return;
                                }
                        }
                        this->Image1->Picture->SaveToFile(SaveDialog1->FileName);
                        MessageBox(NULL,"保存成功","OK",MB_OK);
                        Action=caFree;
                        iForm2Sum--;
                        bForm2Null[iOrder]=true;
                        Form3->ListBox1->Clear();
                        for(i=0;i<iPicNum;i++)
                                delete bPicArray[i];
                }
                else
                {
                        Action=caNone;
                        return;
                }
        }
        else if(i==IDNO)
        {
                Action=caFree;
                iForm2Sum--;
                bForm2Null[iOrder]=true;
                Form3->ListBox1->Clear();
                for(i=0;i<iPicNum;i++)
                        delete bPicArray[i];
        }
        else
        {
                 Action=caNone;
                return;
        }
        Form1->StatusBar2->Panels->Items[2]->Text=" ";
        Form1->StatusBar2->Panels->Items[3]->Text=" ";
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormActivate(TObject *Sender)
{
        SetForm3List();  //设定列表
        pProcessBegin.x=pPBegin.x;
        pProcessBegin.y=pPBegin.y;
        pProcessEnd.x=pPEnd.x;
        pProcessEnd.y=pPEnd.y;
        iActForm2=iOrder;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Image1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        if(Shift.Contains(ssRight)||!iGraphStyle)
        {
                iGraphStyle=0;
                Image1->Cursor=crArrow;
                Shape1->Visible=false;
                Image1->Canvas->Pen->Mode=pmCopy;
                Form1->Panel3->Visible=false;
                Form1->Panel4->Visible=false;
                Form3->SpeedButton4->Down=true;
                return;
        }
        preP.x=X;
        preP.y=Y;
        switch(iGraphStyle){
                case 1:          //选择
                        Shape1->Shape=stRectangle;
                        break;
                case 2:          //点
                        Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)]=tGraphColor;
                        return;
                case 3:          //线
                        Image1->Canvas->Pen->Mode=pmNot;
                        curP.x=X*(1 - 0.2*iZoom);
                        curP.y=Y*(1 - 0.2*iZoom);
                        break;
                case 4:          //矩形
                        Shape1->Shape=stRectangle;
                        break;
                case 5:          //椭圆
                        Shape1->Shape=stEllipse;
                        break;
                case 6:           //历史
                        f_imagePointProcess(6,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        break;
                case 7:           //橡皮擦
                        f_imagePointProcess(7,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        break;
                case 8:           //吸管
                        tTempColor=Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)];
                        Form3->Shape1->Brush->Color=tTempColor;
                        Form1->StatusBar2->Panels->Items[1]->Text="RGB: ("+IntToStr(GetRValue(tTempColor))+","+IntToStr(GetGValue(tTempColor))+","+IntToStr(GetBValue(tTempColor))+")";
                        break;
                case 9:           //平滑
                        break;
                default :
                        break;
        }
        if(iGraphStyle==1||iGraphStyle==4||iGraphStyle==5)
        {
                Shape1->Top=Y;
                Shape1->Left=X;
                Shape1->Width=1;
                Shape1->Height=1;
                Shape1->Visible=true;
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Image1MouseMove(TObject *Sender, TShiftState Shift,
      int X, int Y)
{
        Form1->StatusBar2->Panels->Items[2]->Text="X: "+IntToStr((int)(X*(1 - 0.2*iZoom)));
        Form1->StatusBar2->Panels->Items[3]->Text="Y: "+IntToStr((int)(X*(1 - 0.2*iZoom)));
        if(!Shift.Contains(ssLeft)||!iGraphStyle)
                return;

        switch(iGraphStyle){
                case 1:               //选择
                        Shape1->Width=X - preP.x;
                        Shape1->Height=Y - preP.y;
                        //
                        break;
                case 2:              //点
                        Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)]=tGraphColor;
                        break;
                case 3:               //线
                        Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
                        Image1->Canvas->LineTo(curP.x,curP.y);
                        Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
                        Image1->Canvas->LineTo(X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        curP.x=X*(1 - 0.2*iZoom);
                        curP.y=Y*(1 - 0.2*iZoom);
                        break;
                case 4:               //矩形
                        Shape1->Width=X - preP.x;
                        Shape1->Height=Y - preP.y;
                        break;
                case 5:               //椭圆
                        Shape1->Width=X - preP.x;
                        Shape1->Height=Y - preP.y;
                        break;
                case 6:               //历史
                        f_imagePointProcess(6,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        break;
                case 7:               //橡皮擦
                        f_imagePointProcess(7,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        break;
                case 8:               //吸管
                        break;
                case 9:               //平滑
                        break;
                default:
                        break;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Image1MouseUp(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
        if(Shift.Contains(ssRight)||!iGraphStyle||iGraphStyle==2)
                return;
        if(iGraphStyle==3||iGraphStyle==4||iGraphStyle==5)
        {
                Image1->Canvas->Pen->Mode=pmCopy;
                Image1->Canvas->Pen->Width=iGraphThick;
                Image1->Canvas->Pen->Color=tGraphColor;
                if(bIsTransparence)
                        Image1->Canvas->Brush->Style=bsClear;
                else
                {
                        Image1->Canvas->Brush->Style=bsSolid;
                        Image1->Canvas->Brush->Color=tBrushColor;
                }
        }
        switch(iGraphStyle){
                case 1:                   //选择
                        pProcessBegin.x=Shape1->Left*(1 - 0.2*iZoom);
                        pProcessBegin.y=Shape1->Top*(1 - 0.2*iZoom);
                        pProcessEnd.x=(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom);
                        pProcessEnd.y=(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom);
                        if(pProcessBegin.x>pProcessEnd.x)
                        {
                                iR=pProcessEnd.x;
                                pProcessEnd.x=pProcessBegin.x;
                                pProcessBegin.x=iR;
                        }
                        if(pProcessBegin.y>pProcessEnd.y)
                        {
                                iR=pProcessEnd.y;
                                pProcessEnd.y=pProcessBegin.y;
                                pProcessBegin.y=iR;
                        }
                        if(pProcessBegin.x<0)
                                pProcessBegin.x=0;
                        if(pProcessBegin.y<0)
                                pProcessBegin.y=0;
                        if(pProcessEnd.x>=lPicWidth)
                                pProcessEnd.x=lPicWidth-1;
                        if(pProcessEnd.y>=lPicHeight)
                                pProcessEnd.y=lPicHeight-1;
                        break;
                case 3:                   //线
                        Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
                        Image1->Canvas->LineTo(X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
                        break;
                case 4:                   //矩形
                        Image1->Canvas->Rectangle(Shape1->Left*(1 - 0.2*iZoom),Shape1->Top*(1 - 0.2*iZoom),(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom),(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom));
                        Shape1->Visible=false;
                        break;
                case 5:                  //椭圆
                        Image1->Canvas->Ellipse(Shape1->Left*(1 - 0.2*iZoom),Shape1->Top*(1 - 0.2*iZoom),(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom),(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom));
                        Shape1->Visible=false;
                        break;
                case 6:                  //历史
                        break;
                case 7:                  //橡皮擦
                        break;
                case 8:                  //吸管
                        break;
                case 9:                  //平滑
                        break;
                case 100:                  //放大
                        f_imageZoom(true);
                        break;
                case 101:                 //缩小
                        f_imageZoom(false);
                        break;
                default :
                        break;
        }
}
//---------------------------------------------------------------------------
//图像放大
void TForm2::f_imageZoom(bool zoomBS)
{
        if(zoomBS)
                if(iZoom>=iMaxZoom)
                {
                        Image1->Cursor=14;
                        return;
                }
                else
                {
                        Image1->Cursor=12;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -