Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- namespace БуферОбменаSaveBMP {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <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::SaveFileDialog^ saveFileDialog1;
- private: System::Windows::Forms::Panel^ panel1;
- private: System::Windows::Forms::PictureBox^ pictureBox1;
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::Button^ button2;
- protected:
- private:
- /// <summary>
- /// Требуется переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Обязательный метод для поддержки конструктора - не изменяйте
- /// содержимое данного метода при помощи редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
- this->panel1 = (gcnew System::Windows::Forms::Panel());
- this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->panel1->SuspendLayout();
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
- this->SuspendLayout();
- //
- // panel1
- //
- this->panel1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
- | System::Windows::Forms::AnchorStyles::Left)
- | System::Windows::Forms::AnchorStyles::Right));
- this->panel1->Controls->Add(this->pictureBox1);
- this->panel1->Location = System::Drawing::Point(12, 12);
- this->panel1->Name = L"panel1";
- this->panel1->Size = System::Drawing::Size(325, 224);
- this->panel1->TabIndex = 3;
- //
- // pictureBox1
- //
- this->pictureBox1->Location = System::Drawing::Point(3, 3);
- this->pictureBox1->Name = L"pictureBox1";
- this->pictureBox1->Size = System::Drawing::Size(312, 189);
- this->pictureBox1->TabIndex = 0;
- this->pictureBox1->TabStop = false;
- //
- // button1
- //
- this->button1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
- this->button1->Location = System::Drawing::Point(12, 242);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(239, 23);
- this->button1->TabIndex = 0;
- this->button1->Text = L"button1";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // button2
- //
- this->button2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
- this->button2->Location = System::Drawing::Point(276, 242);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(51, 23);
- this->button2->TabIndex = 2;
- this->button2->Text = L"Re-get bitmap image";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(339, 277);
- this->Controls->Add(this->panel1);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->button1);
- this->Name = L"Form1";
- this->Text = L"Form1";
- this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
- this->panel1->ResumeLayout(false);
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
- this->ResumeLayout(false);
- }
- #pragma endregion
- // Программа читает буфер обмена, и если данные в нем представлены
- // в формате растровой графики, то записывает их в BMP-файл
- private: System::
- Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
- {
- //panel1->Size = Drawing::Size(200, 151);
- this->Text = "Сохраняю копию БО в BMP-файл";
- button1->Text = "Сохранить";
- //pictureBox1->Size = Drawing::Size(184, 142);
- pictureBox1->SizeMode = PictureBoxSizeMode::AutoSize; //ScretchImage - сжатие\растягивание изображения
- panel1->AutoScroll = true;
- button2->PerformClick();
- }
- private: System::Void button1_Click(System::Object^ sender,
- System::EventArgs^ e)
- {
- // Объявление объекта-получателя из буфера обмена
- auto Получатель = Clipboard::GetDataObject();
- Bitmap ^ Растр;
- // Если данные в буфере обмена представлены в формате Bitmap...
- if (Получатель->GetDataPresent(DataFormats::Bitmap))
- { // то записать их из БО в переменную Растр в формате Bitmap
- Растр = (Bitmap^)Получатель->GetData(DataFormats::Bitmap);
- //ЗДЕСЬ КАРТИНКА ДОЛЖНА ОБРЕЗАТЬСЯ
- saveFileDialog1->Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
- saveFileDialog1->Title = "Save screenshot";
- saveFileDialog1->RestoreDirectory = true;
- if(saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
- {
- switch(saveFileDialog1->FilterIndex)
- {
- case 1 :
- this->pictureBox1->Image->Save(saveFileDialog1->FileName, System::Drawing::Imaging::ImageFormat::Jpeg);
- break;
- case 2 :
- this->pictureBox1->Image->Save(saveFileDialog1->FileName, System::Drawing::Imaging::ImageFormat::Bmp);
- break;
- case 3 :
- this->pictureBox1->Image->Save(saveFileDialog1->FileName, System::Drawing::Imaging::ImageFormat::Gif);
- break;
- }
- MessageBox::Show("Изображение из БО записано в файл: " + saveFileDialog1->ToString());
- }
- }
- else
- // В БО нет данных в формате изображений
- MessageBox::Show("В буфере обмена нет данных в формате Bitmap", "Запишите какое-либо изображение в БО");
- }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- IDataObject ^ Получатель = Clipboard::GetDataObject();
- Bitmap ^ Растр;
- // Если данные в БО представлены в формате Bitmap...
- if (Получатель->GetDataPresent(DataFormats::Bitmap) == true)
- { // то записать эти данные из БО в переменную
- // Растр в формате Bitmap:
- Растр = (Bitmap^)Получатель->GetData(DataFormats::Bitmap);
- pictureBox1->Image = Растр;
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement