画像切り出しプログラム

本物のページはこちら→image-clip

Included page "dotnet:image-clip" does not exist (create it now)

スクリーンショット

sample.png

ダウンロード

executable .NetFramefowrkが入ってないと動かない。

ソースコード

#pragma once
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#define BOTTOMOFFSET 85
#define RIGHTOFFSET 79
//白い四角を描くための変数
int beginX,beginY=0;
int endX,endY=0;
 int bX,bY,eX,eY=0;
int realWidth,realHeight=0;
 float scaleX=1.0f;
 float scaleY=1.0f;
bool endDrawFlag=true;
 bool mouseMovingFlag=false;
 float aspectRatio=1.0;
namespace clippingForm {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;
    using namespace System::Text;//for encoding
    //using namespace System::Threading;//for progress bar
 
    /// <summary>
    /// Form1 の概要
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: ここにコンストラクター コードを追加します
            //
        }
 
    protected:
        /// <summary>
        /// 使用中のリソースをすべてクリーンアップします。
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  fileSelectButton;
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::Label^  label1;
    private: System::Windows::Forms::PictureBox^  pictureBox;
    //Bitmap ^bitmap ;
    Point ^location;
    public: String ^filepath;
    public: String ^initialDirectory;
    public: System::Drawing::Size ^pictBoxSize;
 
    protected: 
 
    protected: 
 
    private:
        /// <summary>
        /// 必要なデザイナー変数です。
        /// </summary>
        System::ComponentModel::Container ^components;
 
    private: System::Windows::Forms::TextBox^  beginXtext;
    private: System::Windows::Forms::TextBox^  beginYtext;
    private: System::Windows::Forms::TextBox^  endXtext;
    private: System::Windows::Forms::Label^  beginPont;
    private: System::Windows::Forms::Label^  endPoint;
    private: System::Windows::Forms::Button^  saveButton;
    private: System::Windows::Forms::Label^  XYText;
    private: System::Windows::Forms::Label^  outPutFileText;
    private: System::Windows::Forms::Label^  originalFileText;
    private: System::Windows::Forms::TextBox^  prefixText;
 
    private: System::Windows::Forms::Label^  postfix;
    private: System::Windows::Forms::CheckBox^  checkBox1;
    private: System::Windows::Forms::TextBox^  foldername;
    private: System::Windows::Forms::ProgressBar^  progressBar1;
    private: System::Windows::Forms::Label^  label2;
    private: System::Windows::Forms::Label^  label3;
    private: System::Windows::Forms::TextBox^  maximumImageNum;
    private: System::Windows::Forms::TextBox^  endYtext;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディターで変更しないでください。
        /// </summary>
        void InitializeComponent(void)
        {
            this->fileSelectButton = (gcnew System::Windows::Forms::Button());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->pictureBox = (gcnew System::Windows::Forms::PictureBox());
            this->beginXtext = (gcnew System::Windows::Forms::TextBox());
            this->beginYtext = (gcnew System::Windows::Forms::TextBox());
            this->endXtext = (gcnew System::Windows::Forms::TextBox());
            this->endYtext = (gcnew System::Windows::Forms::TextBox());
            this->beginPont = (gcnew System::Windows::Forms::Label());
            this->endPoint = (gcnew System::Windows::Forms::Label());
            this->saveButton = (gcnew System::Windows::Forms::Button());
            this->XYText = (gcnew System::Windows::Forms::Label());
            this->outPutFileText = (gcnew System::Windows::Forms::Label());
            this->originalFileText = (gcnew System::Windows::Forms::Label());
            this->prefixText = (gcnew System::Windows::Forms::TextBox());
            this->postfix = (gcnew System::Windows::Forms::Label());
            this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
            this->foldername = (gcnew System::Windows::Forms::TextBox());
            this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->maximumImageNum = (gcnew System::Windows::Forms::TextBox());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox))->BeginInit();
            this->SuspendLayout();
            // 
            // fileSelectButton
            // 
            this->fileSelectButton->Location = System::Drawing::Point(344, 12);
            this->fileSelectButton->Name = L"fileSelectButton";
            this->fileSelectButton->Size = System::Drawing::Size(164, 39);
            this->fileSelectButton->TabIndex = 0;
            this->fileSelectButton->Text = L"ファイルを選択する";
            this->fileSelectButton->UseVisualStyleBackColor = true;
            this->fileSelectButton->Click += gcnew System::EventHandler(this, &Form1::fileSelectButton_Click);
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(99, 19);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(234, 19);
            this->textBox1->TabIndex = 1;
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(12, 19);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(81, 12);
            this->label1->TabIndex = 2;
            this->label1->Text = L"選択したファイル";
            // 
            // pictureBox
            // 
            this->pictureBox->BackColor = System::Drawing::SystemColors::GradientActiveCaption;
            this->pictureBox->Location = System::Drawing::Point(344, 66);
            this->pictureBox->Name = L"pictureBox";
            this->pictureBox->Size = System::Drawing::Size(200, 200);
            this->pictureBox->TabIndex = 3;
            this->pictureBox->TabStop = false;
            this->pictureBox->Click += gcnew System::EventHandler(this, &Form1::pictureBox_Click);
            this->pictureBox->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::pictureBox_Paint);
            this->pictureBox->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox_MouseDown);
            this->pictureBox->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox_MouseMove);
            this->pictureBox->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pictureBox_MouseUp);
            // 
            // beginXtext
            // 
            this->beginXtext->Location = System::Drawing::Point(203, 142);
            this->beginXtext->Name = L"beginXtext";
            this->beginXtext->Size = System::Drawing::Size(40, 19);
            this->beginXtext->TabIndex = 4;
            this->beginXtext->TextChanged += gcnew System::EventHandler(this, &Form1::beginXtext_TextChanged);
            // 
            // beginYtext
            // 
            this->beginYtext->Location = System::Drawing::Point(268, 142);
            this->beginYtext->Name = L"beginYtext";
            this->beginYtext->Size = System::Drawing::Size(40, 19);
            this->beginYtext->TabIndex = 5;
            this->beginYtext->TextChanged += gcnew System::EventHandler(this, &Form1::beginYtext_TextChanged);
            // 
            // endXtext
            // 
            this->endXtext->Location = System::Drawing::Point(203, 167);
            this->endXtext->Name = L"endXtext";
            this->endXtext->Size = System::Drawing::Size(40, 19);
            this->endXtext->TabIndex = 6;
            this->endXtext->TextChanged += gcnew System::EventHandler(this, &Form1::endXtext_TextChanged);
            // 
            // endYtext
            // 
            this->endYtext->Location = System::Drawing::Point(268, 167);
            this->endYtext->Name = L"endYtext";
            this->endYtext->Size = System::Drawing::Size(40, 19);
            this->endYtext->TabIndex = 7;
            this->endYtext->TextChanged += gcnew System::EventHandler(this, &Form1::endYtext_TextChanged);
            // 
            // beginPont
            // 
            this->beginPont->AutoSize = true;
            this->beginPont->Location = System::Drawing::Point(139, 143);
            this->beginPont->Name = L"beginPont";
            this->beginPont->Size = System::Drawing::Size(41, 12);
            this->beginPont->TabIndex = 8;
            this->beginPont->Text = L"開始点";
            // 
            // endPoint
            // 
            this->endPoint->AutoSize = true;
            this->endPoint->Location = System::Drawing::Point(139, 170);
            this->endPoint->Name = L"endPoint";
            this->endPoint->Size = System::Drawing::Size(41, 12);
            this->endPoint->TabIndex = 9;
            this->endPoint->Text = L"終了点";
            // 
            // saveButton
            // 
            this->saveButton->Location = System::Drawing::Point(141, 201);
            this->saveButton->Name = L"saveButton";
            this->saveButton->Size = System::Drawing::Size(115, 36);
            this->saveButton->TabIndex = 10;
            this->saveButton->Text = L"画像生成開始";
            this->saveButton->UseVisualStyleBackColor = true;
            this->saveButton->Click += gcnew System::EventHandler(this, &Form1::saveButton_Click);
            // 
            // XYText
            // 
            this->XYText->AutoSize = true;
            this->XYText->Location = System::Drawing::Point(342, 54);
            this->XYText->Name = L"XYText";
            this->XYText->Size = System::Drawing::Size(41, 12);
            this->XYText->TabIndex = 11;
            this->XYText->Text = L"座標値";
            // 
            // outPutFileText
            // 
            this->outPutFileText->AutoSize = true;
            this->outPutFileText->Location = System::Drawing::Point(12, 90);
            this->outPutFileText->Name = L"outPutFileText";
            this->outPutFileText->Size = System::Drawing::Size(128, 12);
            this->outPutFileText->TabIndex = 12;
            this->outPutFileText->Text = L"出来上がるファイルの名前";
            // 
            // originalFileText
            // 
            this->originalFileText->AutoSize = true;
            this->originalFileText->Location = System::Drawing::Point(12, 66);
            this->originalFileText->Name = L"originalFileText";
            this->originalFileText->Size = System::Drawing::Size(119, 12);
            this->originalFileText->TabIndex = 13;
            this->originalFileText->Text = L"オリジナルファイルの名前";
            // 
            // prefixText
            // 
            this->prefixText->Location = System::Drawing::Point(149, 88);
            this->prefixText->Name = L"prefixText";
            this->prefixText->Size = System::Drawing::Size(31, 19);
            this->prefixText->TabIndex = 14;
            this->prefixText->Text = L"mini";
            // 
            // postfix
            // 
            this->postfix->AutoSize = true;
            this->postfix->Location = System::Drawing::Point(209, 91);
            this->postfix->Name = L"postfix";
            this->postfix->Size = System::Drawing::Size(0, 12);
            this->postfix->TabIndex = 15;
            // 
            // checkBox1
            // 
            this->checkBox1->AutoSize = true;
            this->checkBox1->Location = System::Drawing::Point(20, 115);
            this->checkBox1->Name = L"checkBox1";
            this->checkBox1->Size = System::Drawing::Size(156, 16);
            this->checkBox1->TabIndex = 16;
            this->checkBox1->Text = L"フォルダを作る フォルダ名→";
            this->checkBox1->UseVisualStyleBackColor = true;
            // 
            // foldername
            // 
            this->foldername->Location = System::Drawing::Point(173, 114);
            this->foldername->Name = L"foldername";
            this->foldername->Size = System::Drawing::Size(105, 19);
            this->foldername->TabIndex = 17;
            this->foldername->Text = L"mini";
            // 
            // progressBar1
            // 
            this->progressBar1->Location = System::Drawing::Point(63, 243);
            this->progressBar1->Name = L"progressBar1";
            this->progressBar1->Size = System::Drawing::Size(269, 22);
            this->progressBar1->TabIndex = 18;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(4, 247);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(53, 12);
            this->label2->TabIndex = 19;
            this->label2->Text = L"進行状況";
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->Location = System::Drawing::Point(11, 141);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(77, 12);
            this->label3->TabIndex = 20;
            this->label3->Text = L"最大画像枚数";
            // 
            // maximumImageNum
            // 
            this->maximumImageNum->Location = System::Drawing::Point(88, 136);
            this->maximumImageNum->Name = L"maximumImageNum";
            this->maximumImageNum->Size = System::Drawing::Size(43, 19);
            this->maximumImageNum->TabIndex = 21;
            this->maximumImageNum->Text = L"10000";
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(568, 311);
            this->Controls->Add(this->maximumImageNum);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->progressBar1);
            this->Controls->Add(this->foldername);
            this->Controls->Add(this->checkBox1);
            this->Controls->Add(this->postfix);
            this->Controls->Add(this->prefixText);
            this->Controls->Add(this->originalFileText);
            this->Controls->Add(this->outPutFileText);
            this->Controls->Add(this->XYText);
            this->Controls->Add(this->saveButton);
            this->Controls->Add(this->endPoint);
            this->Controls->Add(this->beginPont);
            this->Controls->Add(this->endYtext);
            this->Controls->Add(this->endXtext);
            this->Controls->Add(this->beginYtext);
            this->Controls->Add(this->beginXtext);
            this->Controls->Add(this->pictureBox);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->fileSelectButton);
            this->Name = L"Form1";
            this->Text = L"画像切り出し";
            this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Resize);
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox))->EndInit();
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
#pragma endregion
private: System::Void saveBitmap(String ^str){
 
        }
private: System::Void loadInitFile(){
 
                        // Create an instance of StreamReader to read from a file.
                        // The using statement also closes the StreamReader.
                         StreamReader^ sr = gcnew StreamReader("initfile.txt");
                        {
                            String^ line;
                            // Read and display lines from the file until the end of 
                            // the file is reached.
                            while ((line = sr->ReadLine()) != nullptr) 
                            {
                                initialDirectory=line;
 
                            }
                        }
 
                        sr->Close();
                        if(initialDirectory==""){
                            initialDirectory="C:\\";
                        }
             }
private: System::Void saveInitFile(){
                // Create an instance of StreamWriter to write text to a file.
                // The using statement also closes the StreamWriter.
                // Encoding sjisEnc = Encoding::GetEncoding("Shift_JIS");
                StreamWriter ^sw = gcnew StreamWriter("initfile.txt", false,Encoding::GetEncoding("Shift_JIS")); 
                {
                    // Add some text to the file.//付け足すんじゃなくて、上書きしてほしい。
                    sw->WriteLine(initialDirectory);
                    sw->Close();
                }
             }
private: System::Void fileSelectButton_Click(System::Object^  sender, System::EventArgs^  e) {
                  System::IO::Stream^ myStream;
                  OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
 
                  openFileDialog1->InitialDirectory = initialDirectory;
                  openFileDialog1->Filter = "bmp files (*.bmp)|*.bmp";
                  openFileDialog1->FilterIndex = 2;
                  openFileDialog1->RestoreDirectory = true;
 
                  if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
                  {
                     if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
                     {
                         //String ^filepath= gcnew String("");
 
                        filepath= openFileDialog1->FileName::get();
                        //Path ^filepath = gcnew Path(filename);//filepath= openFileDialog1->FileName::get();
 
                        initialDirectory=Path::GetDirectoryName(filepath);
                        originalFileText->Text="オリジナルファイルの名前:"+Path::GetFileName(filepath);//
                        postfix->Text="_"+Path::GetFileName(filepath);
                        // Insert code to read the stream here.
                        myStream->Close();
                        this->textBox1->Text=filepath;
 
                        refreshImage();
 
                     }
                  }
             }
private: System::Void pictureBox_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
                 //マウスカーソル取得
                 mouseMovingFlag=true;
                beginX=(int)((float)e->X*scaleX);
                beginY=(int)((float)e->Y*scaleY);
                System::String ^str;
                str=str->Format("{0}",beginX,beginY);
                beginXtext->Text=str;
                str=str->Format("{0}",beginY);
                beginYtext->Text=str;
 
                endDrawFlag=false;
                mouseMovingFlag=false;
 
             }
private: System::Void pictureBox_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
 
             mouseMovingFlag=true;    
 
                decideEndPoint(e->X,e->Y);
 
             endDrawFlag=true;
             mouseMovingFlag=false;
         }
private: System::Void pictureBox_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
             Graphics ^g = e->Graphics;
 
             Pen ^myPen = gcnew Pen(Brushes::White);//Color->FromArgb(0 , 0 , 0) , 1);
              // Set the pen's width.
               myPen->Width = 1.0F;
               // Set the LineJoin property.
             myPen->LineJoin = System::Drawing::Drawing2D::LineJoin::Bevel;
 
             if(endX-beginX<0){
                 bX=endX;
                 eX=beginX-endX;
             }else{
                 bX=beginX;
                 eX=endX-beginX;
             }
             if(endY-beginY<0){
                 bY=endY;
                 eY=beginY-endY;
             }else{
                 bY=beginY;
                 eY=endY-beginY;
             }
             realWidth=eX;
             realHeight=eY;
              bX=(int)((float)bX/scaleX); eX=(int)((float)eX/scaleX);
              bY=(int)((float)bY/scaleY); eY=(int)((float)eY/scaleY);
             System::Drawing::Rectangle rect(bX,bY,eX,eY);
             g->DrawRectangle(myPen , rect);
              //Dispose of the pen.
      delete myPen;
 
         }
private: System::Void decideEndPoint(int x,int y){
 
                endX=(int)((float)x*scaleX);
                endY=(int)((float)y*scaleY);
                System::String ^str;
                str=str->Format("{0}",endX);
                endXtext->Text=str;
                str=str->Format("{0}",endY);
                endYtext->Text=str;
                pictureBox->Invalidate();
         }
private: System::Void pictureBox_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
            String ^str = gcnew String("");
             str=str->Format("座標値({0},{1})",(int)((float)e->X*scaleX),(int)((float)e->Y*scaleX));
             XYText->Text=str;
 
             delete str;
             if(!endDrawFlag){
                mouseMovingFlag=true;
                decideEndPoint(e->X,e->Y);
 
                mouseMovingFlag=false;
             }
         }
private: System::Void refreshImage(){
             pictureBox->SizeMode = PictureBoxSizeMode::StretchImage;//自動的に縮小表示する
             pictureBox->Image =Image::FromFile(filepath);//これを入れてから部品が透明になってしまった。
             pictureBox->Invalidate();
             getBitmapInfo(filepath);
         }
private: System::Void getBitmapInfo(String ^filename){
             Image ^img= Image::FromFile(filename);
             scaleX= (float)img->Width /(float)pictureBox->Width;
             scaleY =(float)img->Height /(float)pictureBox->Height;
            aspectRatio=(float)img->Width /(float)img->Height;
 
         }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
             //ここに初期化処理を書く。
             filepath="sample-0.bmp";
 
             pictureBox->SizeMode = PictureBoxSizeMode::StretchImage;//自動的に縮小表示する
             pictureBox->Image =Image::FromFile(filepath);//これを入れてから部品が透明になってしまった。
            location = gcnew Point(344,66);
             pictureBox->Location = *location;
             getBitmapInfo(filepath);
 
            loadInitFile();
            int height=(this->Height - BOTTOMOFFSET) -  location->Y;
              int width=(int)((float)height*aspectRatio);//
                    pictureBox->ClientSize = System::Drawing::Size(width,height);
 
         }
private: System::Void rectangleCheck(){
            // GraphicsUnit units = GraphicsUnit::Pixel;//四角形がはみ出てないかチェック(はみ出てるわけがないけど)
            //RectangleF bounds=bitmap->GetBounds(units);
            //if(bounds.X >beginX || bounds.Y >beginY || bounds.Width<rect.Width || bounds.Height <rect.Height){
            //                    MessageBox::Show("はみ出てる");exit(0);
            //            }
         }
private: System::Void saveButton_Click(System::Object^  sender, System::EventArgs^  e) {
            //もしフォルダを作るボタンがチェックされてたら、フォルダを作るべし
             String ^outputDirectory;
             if(checkBox1->Checked){
                 outputDirectory=initialDirectory+"\\"+foldername->Text;
             System::IO::Directory::CreateDirectory(outputDirectory);
             }else{
                 outputDirectory=initialDirectory;
             }
             System::Drawing::Rectangle rect(beginX,beginY,realWidth,realHeight);//width height    なのに!!
            //resolutionにあわせてカットすべき?
 
            System::String ^filename= Path::GetFileName(filepath);
            int index=filename->IndexOf('-');
            //見つからない場合は-1
            bool error=false;
            if(rect.Width ==0 || rect.Height ==0){MessageBox::Show("長方形の範囲をしてください。");error=true;}
 
            if(!error){if(index!=-1){
                array<String^>^ prefix=filename->Split('-');
                int id=0;
                array<String^>^ numStr=prefix[1]->Split('.');//さらに余分な拡張子をカット
                id=Int32::Parse(numStr[0]);//シードとなるid番号を取得
 
                for(int i=0;i<Int32::Parse(maximumImageNum->Text);i++){
                    String ^newfilepath;
                    String ^originalfilepath;
                    originalfilepath=initialDirectory+"\\"+prefix[0]+"-"+id+".bmp";
 
                    if(File::Exists(originalfilepath)){//次のファイルを探す
 
                        //newfilepath=initialDirectory+"\\mini"+prefix[0]+"\\mini"+prefix[0]+"-"+id+".bmp";
                        newfilepath=outputDirectory+"\\"+prefixText->Text+"_"+prefix[0]+"-"+id+".bmp";
                        Bitmap ^bitmap =gcnew Bitmap(originalfilepath);
 
                            Bitmap ^newBitmap = gcnew Bitmap(rect.Width,rect.Height);
                            //Bitmap ^
                                newBitmap=bitmap->Clone(rect,bitmap->PixelFormat);
                            delete bitmap;
                            newBitmap->Save(newfilepath);
                            delete newBitmap;
            id++;
 
            }else{
 
                    }
                    progressBar1->Value = (int)(100.0*(float)i/(float)Int32::Parse(maximumImageNum->Text));
                //if(i>=Int32::Parse(maximumImageNum->Text))progressBar1->Value = 100;
            }//end i
 
                    MessageBox::Show("画像生成終了");
            }else{
                    MessageBox::Show("error:ファイル名に'-'が含まれていません。画像を選びなおしてください。");
            }
            }
 
         }
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
             saveInitFile();//前回のディレクトリを覚えておくためのもの
         }
private: System::Void beginXtext_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             //これもこれで、マウスによる変更のときも変わるから困る
            if(!mouseMovingFlag){
                if(beginXtext->Text !=""){
                    beginX=Int32::Parse(beginXtext->Text);
                }
                pictureBox->Invalidate();
            }
         }
private: System::Void beginYtext_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             if(!mouseMovingFlag){
                if(beginYtext->Text !=""){
                    beginY=Int32::Parse(beginYtext->Text);
                }
                pictureBox->Invalidate();
            }
         }
private: System::Void endXtext_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             if(!mouseMovingFlag){
                if(endXtext->Text !=""){
                    endX=Int32::Parse(endXtext->Text);
                }
                pictureBox->Invalidate();
            }
         }
private: System::Void endYtext_TextChanged(System::Object^  sender, System::EventArgs^  e) {
             if(!mouseMovingFlag){
                if(endYtext->Text !=""){
                    endY=Int32::Parse(endYtext->Text);
                }
                pictureBox->Invalidate();
            }
         }
private: System::Void Form1_Resize(System::Object^  sender, System::EventArgs^  e) {
             //ダイアログのサイズが変わったときに呼び出される。最大化するときも呼び出される。
             int height=(this->Height - BOTTOMOFFSET) -  location->Y;
              int width=(int)((float)height*aspectRatio);//
              pictureBox->ClientSize = System::Drawing::Size(width,height);
 
              getBitmapInfo(filepath);
 
//sizeは割り算できない!?
         }
private: System::Void pictureBox_Click(System::Object^  sender, System::EventArgs^  e) {
         }
};
}

サポートサイト Wikidot.com