C++Builder ソ−ス フアイル         Return

  • 実行フアイル(c_ImageViwer.zip)
  • ソース フアイル(csrc.zip)


    マウスの左クリックでドラッグして画像の移動が出来るようにしました。

    ImageViiewerコントロ−ルはBMP,PNG、TIFF,アイコン、JPGなどは指定しなくとも、Load,Saveができ、マウスのホイ−ルで画像の拡大、縮小ができ、 スクロ−ル バ−も付いており、一通りの操作は可能でした。
    ImageViewer1->MakeScreenshot()でBMPに表示されている画像が保存できました。

    画像に選択領域の枠を描いたり、切り取ったり(原画像の大きさで)、現在表示されている画像の位置と原画像の位置の関係など、不明な 点が多くあり、FireMonkeyを良く理解できません。素人がプログラムを組むには、情報が少なすぎます。


    配置図
    Formに ImageViewer、Label Panelを配置
    Dialog : OpenDialog, SaveDilog、MainMenu を利用し、フアイルのOpen、Saveのフアイル名を、MainMenuでフアイル、クリップボード、ImageViewer1.MakeScreenshot()でScreen ショットの 保存など動作を指定
    ClipBordの操作はDelphiでは、サンプルがありましたが、C++Builderはサンプルがほとんどなく苦戦しました。
    #include <fmx.h> #pragma hdrstop #include <FMX.Platform.hpp> #include <FMX.Filter.hpp> #include <FMX.Clipboard.hpp> #include <FMX.Surfaces.hpp> #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- String fName; double X0,Y0; int DFlg; String takefile() { String ext,path; int pos; int len; if(Form1->SaveDialog1->Execute()) { ext=ExtractFileExt(Form1->SaveDialog1->FileName); fName=ExtractFileName(Form1->SaveDialog1->FileName); //name+.exe // GetFileNameWithoutExtension('D:\Testing\MyApp.exe.config'); 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=""; } return fName; } void __fastcall TForm1::OpenClick(TObject *Sender) //Open File { if(OpenDialog1->Execute()) { ImageViewer1->Bitmap->LoadFromFile(OpenDialog1->FileName); Label3->Text= OpenDialog1->FileName ; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Screen保存Click(TObject *Sender) //screen { // TBitmapのインスタンス Fmx::Graphics::TBitmap *bitmap; if(SaveDialog1->Execute()) { // TBitmapのインスタンス Fmx::Graphics::TBitmap *bitmap; ImageViewer1->ShowScrollBars=false; bitmap=ImageViewer1->MakeScreenshot(); bitmap->SaveToFile(SaveDialog1->FileName); // 後処理 delete bitmap; ImageViewer1->ShowScrollBars=true; } } //--------------------------------------------------------------------------- void __fastcall TForm1::MenuItem3Click(TObject *Sender) //ClipBoard { _di_IFMXExtendedClipboardService Clipboard; _di_IFMXClipboardService Intf; if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService), &Clipboard)) { if (Clipboard->HasImage ) { ImageViewer1->Bitmap->Assign(Clipboard->GetImage()); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::MenuItem2Click(TObject *Sender) //File Save { String fname; fname=takefile(); if(fname=="") return; try { ImageViewer1->Bitmap->SaveToFile(fname); } catch(...) { ShowMessage("扱える画像形式ではないようです !"); } } //--------------------------------------------------------------------------- void __fastcall TForm1::ImageViewer1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, bool &Handled) { int r; double r0; r=ImageViewer1->BitmapScale*10000; r0=(double)r/10000; Label2->Text= r0; } //----マウス 左クリクでドラッグ、画像の移動----------------------------------------- void __fastcall TForm1::ImageViewer1MouseMove(TObject *Sender, TShiftState Shift, float X, float Y) { double x,y; if(DFlg==255) { x=X-X0; y=Y-Y0; ImageViewer1->ScrollBy(x,y); X0=X; Y0=Y; } } //--------------------------------------------------------------------------- void __fastcall TForm1::ImageViewer1MouseDown(TObject *Sender, TMouseButton Button,TShiftState Shift, float X, float Y) { X0=X; Y0=Y; DFlg=255; } //--------------------------------------------------------------------------- void __fastcall TForm1::ImageViewer1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y) { DFlg=0; } //------ドラッグ 終了---------------------------------------------------------- void __fastcall TForm1::MenuItem7Click(TObject *Sender) //Screen->ClipBord save { _di_IFMXExtendedClipboardService Clipboard; Fmx::Graphics::TBitmap *bitmap; _di_IFMXClipboardService Intf; if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService), &Clipboard)) { ImageViewer1->ShowScrollBars=false; bitmap=ImageViewer1->MakeScreenshot(); Clipboard->SetClipboard(TValue::From(bitmap)); delete bitmap; ImageViewer1->ShowScrollBars=true; } } //--------------------------------------------------------------------------- void __fastcall TForm1::MenuItem6Click(TObject *Sender) { Close(); } //---------------------------------------------------------------------------