Für diesen Befehl ist nicht genügend Speicher verfügbar
-
Ich habe eine Anwendung geschrieben, die ein Bild in eine PictureBox einliest und wenn das Bild zu groß ist soll man die PictureBox mit Scrollbalken verschieben. Doch wenn man Scrollt, kommt folgende Fehlermeldung: Für diesen Befehl ist nicht genügend Speicher verfügbar.
Warum? Ich habe 3GB Arbeitsspeicher und es funktioniert nicht???
-
Es liegt an dem Bild, in der pictureBox. Es ist zu groß. Doch eigentlich müsste mein Arbeitsspeicher reichen. Das Bild hat 26MB. Doch wie kann ich meinem Programm mehr Speicherplatz zuweisen?
-
hab grade mal versuchsweise ne 27mb große bmp erzeugt und sie in ne picturebox eingelesen, lief problemlos (auch mit scrollen)
benutze vc++2008express falls es dir weiterhilft
-
Das ist mein Code:
#pragma once namespace Scan { 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> /// Zusammenfassung für Form1 /// /// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch /// die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern, /// das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt. /// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen /// arbeiten, die diesem Formular zugewiesen sind. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Konstruktorcode hier hinzufügen. // } protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::HScrollBar^ hScrollBar1; protected: private: System::Windows::Forms::VScrollBar^ vScrollBar1; private: System::Windows::Forms::PictureBox^ pictureBox1; private: /// <summary> /// Erforderliche Designervariable. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->hScrollBar1 = (gcnew System::Windows::Forms::HScrollBar()); this->vScrollBar1 = (gcnew System::Windows::Forms::VScrollBar()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); this->SuspendLayout(); // // hScrollBar1 // this->hScrollBar1->Dock = System::Windows::Forms::DockStyle::Bottom; this->hScrollBar1->Location = System::Drawing::Point(0, 245); this->hScrollBar1->Name = L"hScrollBar1"; this->hScrollBar1->Size = System::Drawing::Size(267, 17); this->hScrollBar1->TabIndex = 0; this->hScrollBar1->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &Form1::hScrollBar1_Scroll); // // vScrollBar1 // this->vScrollBar1->Dock = System::Windows::Forms::DockStyle::Right; this->vScrollBar1->Location = System::Drawing::Point(267, 0); this->vScrollBar1->Name = L"vScrollBar1"; this->vScrollBar1->Size = System::Drawing::Size(17, 262); this->vScrollBar1->TabIndex = 1; this->vScrollBar1->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &Form1::vScrollBar1_Scroll); // // pictureBox1 // this->pictureBox1->Location = System::Drawing::Point(0, 0); this->pictureBox1->Margin = System::Windows::Forms::Padding(0); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(267, 245); this->pictureBox1->TabIndex = 2; this->pictureBox1->TabStop = false; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(284, 262); this->Controls->Add(this->hScrollBar1); this->Controls->Add(this->vScrollBar1); this->Controls->Add(this->pictureBox1); this->Name = L"Form1"; this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; this->Text = L"Scan"; 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->pictureBox1))->EndInit(); this->ResumeLayout(false); } #pragma endregion bool change; String^ image; private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { change = false; image = "C:\\Pictures\\Picture.bmp"; pictureBox1->Image = System::Drawing::Image::FromFile(image); pictureBox1->Dock = System::Windows::Forms::DockStyle::None; hScrollBar1->Maximum=pictureBox1->Image->Width - this->Width + vScrollBar1->Width; vScrollBar1->Maximum=pictureBox1->Image->Height - this->Height + hScrollBar1->Height; pictureBox1->Height = this->Height - hScrollBar1->Height; pictureBox1->Width = this->Width - vScrollBar1->Width; change = true; } private: System::Void hScrollBar1_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) { change = false; pictureBox1->Location = System::Drawing::Point(hScrollBar1->Value * (-1), pictureBox1->Location.Y); pictureBox1->Width = pictureBox1->Width + hScrollBar1->Value; change = true; } private: System::Void vScrollBar1_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) { change = false; pictureBox1->Location = System::Drawing::Point(pictureBox1->Location.X, vScrollBar1->Value * (-1)); pictureBox1->Height = pictureBox1->Height + vScrollBar1->Value; change = true; } private: System::Void Form1_Resize(System::Object^ sender, System::EventArgs^ e) { if(change) { hScrollBar1->Maximum=pictureBox1->Image->Width - this->Width + vScrollBar1->Width; vScrollBar1->Maximum=pictureBox1->Image->Height - this->Height + hScrollBar1->Height; pictureBox1->Height = this->Height - hScrollBar1->Height; pictureBox1->Width = this->Width - vScrollBar1->Width; } } }; }
Das funktioniert nicht. Ich kann mit einem Scrollbalken scrollen, doch dann beim zweiten Scrollen mit dem anderen Scrollbalken bringt er die Fehlermeldung.
-
Was passiert wenn du die PictureBox mit AutoSize in ein Panel mit AutoScroll packst? Und auf deine Scrollbars verzichtest?
-
Tausend Dank!
Funktioniert!