//--------------------------------------------------------------------------- //Mytrim //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- TBitmap *OBitmap = new TBitmap(0, 0); int X0,Y0,DFlg,startX,startY,wVal; float X1,Y1,Rw,Rh; float rX0,rY0,mVolX,mVolY,W,H; String takefile() //File の成形( test ->test.jpg ..) { String ext,path,fName; int pos; int len; String t0,t1,t3; if(Form1->SaveDialog1->Execute()) { ext=ExtractFileExt(Form1->SaveDialog1->FileName); fName=ExtractFileName(Form1->SaveDialog1->FileName); //name+.exe pos=fName.Pos0('.'); //extだけなら pos=0 フアイル名だけなら -1 if((fName=="")||(pos==0)) { return ""; } path=ExtractFilePath(Form1->SaveDialog1->FileName); if(ext=="") { fName = Form1->SaveDialog1->FileName+".jpg"; } else { fName = Form1->SaveDialog1->FileName; } return fName; } return ""; } void Disp() { TBitmap *MyBitmap = new TBitmap(0, 0); try { MyBitmap->Assign(OBitmap); // Draw a rectangle on the copy MyBitmap->Canvas->BeginScene(); MyBitmap->Canvas->Stroke->Color = claRed; MyBitmap->Canvas->Stroke->Thickness =StrToFloat(5.0); if(startX>X1) { X0=X1; X1=startX; } if(startY>Y1) { Y0=Y1; Y1=startY; } if(startXLabel4->Text=X1; Form1->Label2->Text=Y0; Form1->Label5->Text=Y1; Form1->Label6->Text=startX; Form1->Label7->Text=startY; //---------------------------- */ if(X0 !=X1) { TRectF MyRect = TRectF(X0, Y0, X1, Y1); MyBitmap->Canvas->DrawRect(MyRect, 20, 20, AllCorners, 1.0); MyBitmap->Canvas->EndScene(); } // Display the result Form1->Image2->Bitmap = MyBitmap; } __finally { delete MyBitmap; } } void __fastcall TForm1::Button1Click(TObject *Sender) //Open { int x,y,x0,y0; if (OpenDialog1->Execute()) { Image1->Bitmap->LoadFromFile(OpenDialog1->FileName); OBitmap->Assign(Form1->Image1->Bitmap); x=Image1->Bitmap->Width; y=Image1->Bitmap->Height; x0=Image2->Width; y0=Image2->Height; Rw=(float)x/x0; Rh=(float)y/y0; Label10->Text=OpenDialog1->FileName; Label11->Text=IntToStr(x)+" x "+IntToStr(y); startX=startY=0; X0=Y0=X1=Y0=Y1=0; Disp(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) //Save File { String fname; fname=takefile(); if(fname=="") return; try { Image3->Bitmap->SaveToFile(fname); } catch(...) { ShowMessage("扱える画像形式ではないようです !"); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y) { Image2->Cursor=crHandPoint; if((int)Button==0) //mbLeft { X0=X; Y0=Y; DFlg=255; startX=X0=Rw*X0; startY=Y0=Rh*Y0; X1=X0; Y1=Y0; Form1->Image2->Bitmap=OBitmap; Form1->Image1->Bitmap=OBitmap; } else //mbRightck { rX0=X*Rw; rY0=Y*Rh; W=X1-X0; H=Y1-Y0; DFlg=200; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift, float X, float Y) { if(DFlg==255) { X1=X*Rw; Y1=Y*Rh; Disp(); } else if(DFlg==200) { mVolX=X*Rw-rX0; mVolY=Y*Rh-rY0; rX0=X*Rw; rY0=Y*Rh; startX=X0=X0+mVolX; startY=Y0=Y0+mVolY; X1=X0+W; Y1=Y0+H; Disp(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y) { DFlg=0; TRect Rect=TRect(X0,Y0,X1,Y1); TBitmap *MyBitmap = new TBitmap(X1-X0,Y1-Y0 ); // TBitmap *MyBitmap = new TBitmap(0,0 ); // MyBitmap->CopyFromBitmap(Image2->Bitmap,Rect,0,0); MyBitmap->CopyFromBitmap(OBitmap,Rect,0,0); Image3->Bitmap->Assign(MyBitmap); // Image3->Bitmap=MyBitmap; // delete MyBitmap; MyBitmap->Free(); startX=X0; startY=Y0; Image2->Cursor=crDefault; } //--------------------------------------------------------------------------- void __fastcall TForm1::Image2MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, bool &Handled) { wVal=(WheelDelta/120)*StrToInt(NumberBox1->Text); if(CheckBox1->IsChecked==true) { if(CheckBox2->IsChecked==true)//Left { startX=startX-wVal; X0=startX*-1; } if(CheckBox3->IsChecked==true) //Upper { startY=startY-wVal; Y0=startY; } if(CheckBox4->IsChecked==true) //Under { Y1=Y1+wVal; } if(CheckBox5->IsChecked==true) //Right { X1=X1+wVal; } Disp(); TRect Rect=TRect(X0,Y0,X1,Y1); TBitmap *MyBitmap = new TBitmap(X1-X0,Y1-Y0 ); MyBitmap->CopyFromBitmap(Image2->Bitmap,Rect,0,0); //Image1->Bitmap->Assign(MyBitmap); Image3->Bitmap=MyBitmap; // delete MyBitmap; MyBitmap->Free(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::CheckBox1Change(TObject *Sender) { CheckBox2->IsChecked=false; CheckBox3->IsChecked=false; CheckBox4->IsChecked=false; CheckBox5->IsChecked=false; } //---------------------------------------------------------------------------