Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка Windows Forms > заголовок bmp-файла


Автор: sergy 29.12.2007, 11:50
Здравствуйте. С визуал С работаю. всего 2 месяца. В универе дали задание на курсовой проект: создание программы для сравнения 2 изображений bmp по их заголовкам. Оболочку программы сделал:

Код

#pragma once
namespace paral
{
    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> 
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the 
    ///          'Resource File Name' property for the managed resource compiler tool 
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>
    public __gc class Form1 : public System::Windows::Forms::Form
    {
        String * error;
    public:
        Form1(void)
        {
            InitializeComponent();
        }
  
    protected:
        void Dispose(Boolean disposing)
        {
            if (disposing && components)
            {
                components->Dispose();
            }
            __super::Dispose(disposing);
        }
    private: System::Windows::Forms::MainMenu *  mainMenu1;
    private: System::Windows::Forms::MenuItem *  menuItem1;
    private: System::Windows::Forms::MenuItem *  menuItem2;
    private: System::Windows::Forms::MenuItem *  menuItem3;
    private: System::Windows::Forms::MenuItem *  menuItem4;
    private: System::Windows::Forms::MenuItem *  menuItem5;
    private: System::Windows::Forms::MenuItem *  menuItem6;
    private: System::Windows::Forms::MenuItem *  menuItem7;
    private: System::Windows::Forms::MenuItem *  menuItem8;
    private: System::Windows::Forms::PictureBox *  pictureBox1;
    private: System::Windows::Forms::PictureBox *  pictureBox2;
    private: System::Windows::Forms::OpenFileDialog *  openFileDialog1;
    private: System::Windows::Forms::OpenFileDialog *  openFileDialog2;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container * components;

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            System::Resources::ResourceManager *  resources = new System::Resources::ResourceManager(__typeof(paral::Form1));
            this->mainMenu1 = new System::Windows::Forms::MainMenu();
            this->menuItem1 = new System::Windows::Forms::MenuItem();
            this->menuItem2 = new System::Windows::Forms::MenuItem();
            this->menuItem3 = new System::Windows::Forms::MenuItem();
            this->menuItem4 = new System::Windows::Forms::MenuItem();
            this->menuItem5 = new System::Windows::Forms::MenuItem();
            this->menuItem6 = new System::Windows::Forms::MenuItem();
            this->menuItem7 = new System::Windows::Forms::MenuItem();
            this->menuItem8 = new System::Windows::Forms::MenuItem();
            this->pictureBox1 = new System::Windows::Forms::PictureBox();
            this->pictureBox2 = new System::Windows::Forms::PictureBox();
            this->openFileDialog1 = new System::Windows::Forms::OpenFileDialog();
            this->openFileDialog2 = new System::Windows::Forms::OpenFileDialog();
            this->SuspendLayout();
            // 
            // mainMenu1
            // 
            System::Windows::Forms::MenuItem* __mcTemp__1[] = new System::Windows::Forms::MenuItem*[2];
            __mcTemp__1[0] = this->menuItem1;
            __mcTemp__1[1] = this->menuItem6;
            this->mainMenu1->MenuItems->AddRange(__mcTemp__1);
            // 
            // menuItem1
            // 
            this->menuItem1->Index = 0;
            System::Windows::Forms::MenuItem* __mcTemp__2[] = new System::Windows::Forms::MenuItem*[4];
            __mcTemp__2[0] = this->menuItem2;
            __mcTemp__2[1] = this->menuItem3;
            __mcTemp__2[2] = this->menuItem4;
            __mcTemp__2[3] = this->menuItem5;
            this->menuItem1->MenuItems->AddRange(__mcTemp__2);
            this->menuItem1->Text = S"Файл";
            // 
            // menuItem2
            // 
            this->menuItem2->Index = 0;
            this->menuItem2->Text = S"Начать анализ";
            this->menuItem2->Click += new System::EventHandler(this, menuItem2_Click);
            // 
            // menuItem3
            // 
            this->menuItem3->Index = 1;
            this->menuItem3->Text = S"Новый проект";
            this->menuItem3->Click += new System::EventHandler(this, menuItem3_Click);
            // 
            // menuItem4
            // 
            this->menuItem4->Index = 2;
            this->menuItem4->Text = S"-";
            // 
            // menuItem5
            // 
            this->menuItem5->Index = 3;
            this->menuItem5->Text = S"Выход";
            this->menuItem5->Click += new System::EventHandler(this, menuItem5_Click);
            // 
            // menuItem6
            // 
            this->menuItem6->Index = 1;
            System::Windows::Forms::MenuItem* __mcTemp__3[] = new System::Windows::Forms::MenuItem*[2];
            __mcTemp__3[0] = this->menuItem7;
            __mcTemp__3[1] = this->menuItem8;
            this->menuItem6->MenuItems->AddRange(__mcTemp__3);
            this->menuItem6->Text = S"Проект";
            // 
            // menuItem7
            // 
            this->menuItem7->Index = 0;
            this->menuItem7->Text = S"Открыть изображение 1";
            this->menuItem7->Click += new System::EventHandler(this, menuItem7_Click);
            // 
            // menuItem8
            // 
            this->menuItem8->Index = 1;
            this->menuItem8->Text = S"Открыть изображение 2";
            this->menuItem8->Click += new System::EventHandler(this, menuItem8_Click);
            // 
            // pictureBox1
            // 
            this->pictureBox1->Dock = System::Windows::Forms::DockStyle::Left;
            this->pictureBox1->Location = System::Drawing::Point(0, 0);
            this->pictureBox1->Name = S"pictureBox1";
            this->pictureBox1->Size = System::Drawing::Size(144, 361);
            this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::AutoSize;
            this->pictureBox1->TabIndex = 0;
            this->pictureBox1->TabStop = false;
            // 
            // pictureBox2
            // 
            this->pictureBox2->Dock = System::Windows::Forms::DockStyle::Right;
            this->pictureBox2->Location = System::Drawing::Point(144, 0);
            this->pictureBox2->Name = S"pictureBox2";
            this->pictureBox2->Size = System::Drawing::Size(136, 361);
            this->pictureBox2->SizeMode = System::Windows::Forms::PictureBoxSizeMode::AutoSize;
            this->pictureBox2->TabIndex = 1;
            this->pictureBox2->TabStop = false;
            // 
            // openFileDialog1
            // 
            this->openFileDialog1->Filter = S"(*.bmp)|*bmp";
            this->openFileDialog1->FileOk += new System::ComponentModel::CancelEventHandler(this, openFileDialog1_FileOk);
            // 
            // openFileDialog2
            // 
            this->openFileDialog2->Filter = S"(*.bmp)|*.bmp";
            this->openFileDialog2->FileOk += new System::ComponentModel::CancelEventHandler(this, openFileDialog2_FileOk);
            // 
            // Form1
            // 
            this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
            this->ClientSize = System::Drawing::Size(280, 281);
            this->Controls->Add(this->pictureBox2);
            this->Controls->Add(this->pictureBox1);
            this->Icon = (__try_cast<System::Drawing::Icon *  >(resources->GetObject(S"$this.Icon")));
            this->Menu = this->mainMenu1;
            this->Name = S"Form1";
            this->Text = S"Сравнение bmp-изображений";
            this->Load += new System::EventHandler(this, Form1_Load);
            this->ResumeLayout(false);

        }    
    private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
             {
             }

private: System::Void menuItem7_Click(System::Object *  sender, System::EventArgs *  e)
         {
             if(openFileDialog1->ShowDialog()==DialogResult::OK)
             {
if(openFileDialog1->FilterIndex==1)
pictureBox1->Image = Image::FromFile(openFileDialog1->FileName,"\\*.bmp");
             }
         }

private: System::Void openFileDialog1_FileOk(System::Object *  sender, System::ComponentModel::CancelEventArgs *  e)
         {
         }

private: System::Void openFileDialog2_FileOk(System::Object *  sender, System::ComponentModel::CancelEventArgs *  e)
         {
         }

private: System::Void menuItem8_Click(System::Object *  sender, System::EventArgs *  e)
         {
                         if(openFileDialog2->ShowDialog()==DialogResult::OK)
             {
if(openFileDialog2->FilterIndex==1)
pictureBox2->Image = Image::FromFile(openFileDialog2->FileName,"\\*.bmp");
         }

         }

private: System::Void menuItem3_Click(System::Object *  sender, System::EventArgs *  e)
         {
             if (pictureBox1->Image != NULL)
{
   pictureBox1->Image->Dispose();
   pictureBox1->Image = NULL;
}
if (pictureBox2->Image != NULL)
{
   pictureBox2->Image->Dispose();
   pictureBox2->Image = NULL;
}
if(error != NULL){
error = NULL;
}

         }
private: System::Void menuItem5_Click(System::Object *  sender, System::EventArgs *  e)
         {
             this->Close();
         }
private: System::Void menuItem2_Click(System::Object *  sender, System::EventArgs *  e)
         {
             if (pictureBox1->Image == NULL && pictureBox2->Image == NULL) {
error = "Вы не указали изображения для сравнения.";
             }
             else {
             if (pictureBox1->Image == NULL) {
error = "Вы не указали первое изображение.";
             }
              if (pictureBox2->Image == NULL) {
error = "Вы не указали второе изображение.";
              }
             }
             if (!error){

             MessageBox::Show("Ниже приведён список параметров по которым был проведён анализ, а также имя файла значение которого, по субьективному мнению, имеет преимущество перед вторым файлом.\n\n Результаты тут...", "Результаты анализа файлов",
                 MessageBoxButtons::OK,MessageBoxIcon::Information);
             }
             else {
                 MessageBox::Show(error, "Обнаружена ошибка",
                 MessageBoxButtons::OK,MessageBoxIcon::Information);
                 error = NULL;
             }
         }
};
}





И теперь настал момент когда необходимо получить информацию к примеру о размере  файлов, но я не знаю как. Уже неделю по всему инету брожу в поисках каких-либо примеров, нашёл море инфы о структуре заголовков но вот как мне получить к примеру в переменную  размер изображения не могу понять. Обращаюсь к вам с надеждой что подскажете как это делается.

Заранее спасибо

З.Ы. похожие темы были но мне кажется, что задача немного иная. если неправ прошу простить smile

Автор: Dominus 31.12.2007, 16:01
неплохая статья http://jenyay.net/index.php?id=bmp
смотри второй пример,а именно
Цитата

ReadFile (hIn, &bih, sizeof(bih), &RW, NULL);


Автор: Freak_FB 9.1.2008, 15:49
Я может чего-то недопонял: а какие именно свойства из заголовка необходимо сравнивать? Например, размеры изображения можно определить через свойства класса Bitmap. То же самое и с многими другими аттрибутами.

Автор: sergy 9.1.2008, 22:14
Цитата(Freak_FB @ 9.1.2008,  15:49)
Я может чего-то недопонял: а какие именно свойства из заголовка необходимо сравнивать? Например, размеры изображения можно определить через свойства класса Bitmap. То же самое и с многими другими аттрибутами.

Любые свойства. В том то и проблема что мне удалось получить класс Bitmap. Программу написал, так что вопрос в принципе закрыт.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)