Probleme mit Draw
-
Hallo Cracks!
Ich benutze BCB5 und habe folgendes Problem:
Ich möchte,das ein zur Laufzeit erzeugtes und geladenes TPicture direkt auf dem Form ausgegeben wird.
Müsste doch mit Draw gehen, oder?
Habe bisher diesen Code und wundere mich das ich weder Bild,
noch Fehlermeldung bekomme:#include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; TPicture *Bild; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Bild=new TPicture(); Bild->LoadFromFile("C:\\Eigene Dateien\\Bilder\\snap\\snap000001.jpg"); Form1->Canvas->Draw(0,0,Bild->Graphic); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { delete Bild; } //---------------------------------------------------------------------------Warscheinlich ein dummer Fehler...
Hoffe jemand kann mir helfen!Danke!
WerdNochWahnsinnig
-
Hallo
das solltest du etwas anders machen:
im Header :... private : TBitmap *Bild; // Zwischenspeicher für Bild public : ... __fastcall ~TForm1(); // zusätzlicher Destruktorin der Implementation :
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Bild = new Graphics::TBitmap(); Bild->LoadFromFile("C:\\Eigene Dateien\\Bilder\\snap\\snap000001.jpg"); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) // anstatt Create! { Canvas->Draw(0,0,Bild->Graphic); } //--------------------------------------------------------------------------- void __fastcall TForm1::~TForm1() { delete Bild; } //---------------------------------------------------------------------------/Edit : und warum nimmst du dafür nicht gleich ein regulares TImage auf der Form?
bis bald
akari
-
Danke für die schnelle Hilfe!
Hab den Code jetzt so verändert:
Header://--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ExtCtrls.hpp> #include <jpeg.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // Von der IDE verwaltete Komponenten void __fastcall FormCreate(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormPaint(TObject *Sender); private: // Anwender-Deklarationen TBitmap *Bild; public: // Anwender-Deklarationen __fastcall TForm1(TComponent* Owner); __fastcall ~TForm1(); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endifUnd :
#include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //TPicture *Bild; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Canvas->Draw(0,0,Bild->Graphic); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { delete Bild; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Draw(0,0,Bild->Graphic); } //---------------------------------------------------------------------------Doch er wirft mir folgende Fehlermeldungen raus:
[C++ Fehler] Unit1.h(20): E2015 Mehrdeutigkeit zwischen 'TBitmap' und 'Windows::TBitmap'
[C++ Fehler] Unit1.cpp(22): E2316 'Graphic' ist kein Element von 'TBitmap'
[C++ Fehler] Unit1.cpp(32): E2316 'Graphic' ist kein Element von 'TBitmap'Warum???
-
Sorry,akari
Die Sache hab ich natürlich rausgenommen:void __fastcall TForm1::FormCreate(TObject *Sender) { Canvas->Draw(0,0,Bild->Graphic); }Mein Fehler jetzt
-
Hallo
Hab im Header mich verschrieben, es muß so aussehen :
Graphics::TBitmap *Bild;und vergiß die Zeilen im Konstruktor und Destruktor nicht. Nimm das OnClose und das OnCreate raus.
bis bald
akari
-
Geht aber immer noch nicht...
-
brauche ein Weilchen zum testen...
Danke, akari
-
Hallo akari
Hat ja doch noch geklappt:Header:
#ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ExtCtrls.hpp> #include <jpeg.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // Von der IDE verwaltete Komponenten void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall FormPaint(TObject *Sender); private: // Anwender-Deklarationen Graphics::TPicture *Bild; public: // Anwender-Deklarationen __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endifUnit1:
#include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //TPicture *Bild; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Bild = new Graphics::TPicture(); Bild->LoadFromFile("C:\\Eigene Dateien\\Bilder\\snap\\snap000001.jpg"); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { delete Bild; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { Canvas->Draw(0,0,Bild->Graphic); }Danke nochmal, akari !