Bitmap Image is not Valid

This is a discussion on Bitmap Image is not Valid within the C++ Programming forums, part of the General Programming Boards category; Hello, First of all, sorry for my english. I will try to make me understand. I'm doing a program with ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    Unhappy Bitmap Image is not Valid

    Hello,

    First of all, sorry for my english. I will try to make me understand.

    I'm doing a program with CodeGear C++Builder 2009 that manages a few tables.
    The tables were created with Database Desktop 7.0 (dbd32).

    Between these tables there are a table whose name is 'Evaluation'. His estructure is the follows:
    http://img204.imageshack.us/img204/5281/61508099.jpg

    The marked fields in red are the Graphics objects and its the fields that I think that nor work.

    I do a Post() in this table and works it perfectly. But, when I do a few Post(), saving three or four images by instace, apper this error: Bitmap Image is not Valid.
    http://img195.imageshack.us/img195/6606/78798525.jpg

    This is the visual windows of my program where I save the instance of 'Evaluation'.
    http://img803.imageshack.us/img803/6075/74666256.jpg

    Four of five photos can load in a Tabsheet with this code:

    Code:
    switch(PageControl1->TabIndex)
    		{
    		case 0:
    		if(OpenPictureDialog1->Execute())
    				{
    		DBImage2->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    		DBImage2->CopyToClipboard();
    		DBImage2->PasteFromClipboard();
    				}
    		break;

    This DBImage have a DataSource and DataField correspondent with 'Evaluation'.

    Another of five images use an auxiliar DBImage to copy the content of another DBImage. The code that I use before the Post():

    Code:
    	 DBImage1->CopyToClipboard();
    	 DBImage7->PasteFromClipboard();

    DBImage7 have DataSource and Datafield correspondent with 'Evaluation'.

    The format of this images is usually .jpeg or .jpg.
    My question is: why leaves me save at the beginning and when I do a lot of instances throws this error?

    The tables are not corrupted because I verified them with "Dr. Regener Paradox Table Repair 4".

    Please...HELP. I am completely lost...
    If you have not understood something, please, post and i will try to clarify.

    THANKS

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    cross-posted here -> Bitmap Image is not Valid - C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Quote Originally Posted by Salem View Post
    cross-posted here -> Bitmap Image is not Valid - C++
    Sorry but...I need the maximum help with this.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Well broadcasting (without cross-references) means everyone goes through the basics on EVERY forum (a big waste of effort).
    Plenty of other people have questions as well, and if helpers are wasting time on yours, then someone else gets NO help at all.

    Plus you also assume that we can figure out what you're doing from just 5 lines of code (without any declarations).

    Anyway, is this the interface you're using?
    TGraphic.LoadFromFile Method

    If so, then the first thing I would suggest is adding the code to check for errors (or catch exceptions), and free up resources when you're done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Thank you for all and sorry for my mistakes. I'am a novice and I want to learn a lot of things.

    I not sure of what do you want...Do I have to post all the code of my FORM?

    if this is wrong, ask me to post any part of code in particular.

    This is whole of code of this form Imageshack - 44149021.jpg :

    Code:
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #include <jpeg.hpp>
    #pragma hdrstop
    
    #include "Unit14.h"
    #include "Unit3.h"
    bool expandida=false;
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm14 *Form14;
    //---------------------------------------------------------------------------
    __fastcall TForm14::TForm14(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm14::FormShow(TObject *Sender)
    {
    DoubleBuffered=true;
    Form14->Top=0;
    Form14->Left=0;
    switch(Tag)
    	{
    		case 1:
    		Form14->Caption="Alta de Evaluacion";
    		BitBtn17->Caption="Guardar";
    		Panel2->Enabled=true;
    		Panel4->Enabled=true;
    		Panel5->Enabled=true;
    		DBEdit14->Text=DataModule3->Cursos->Fields->FieldByName("FechaIni")->AsDateTime;
    		DBEdit15->Text=DataModule3->Cursos->Fields->FieldByName("FechaFin")->AsDateTime;
    		DataModule3->Evaluacion->Append();
    		break;
    
    		case 2:
    		Form14->Caption="Consulta de Evaluacion";
    		Panel2->Enabled=false;
    		Panel4->Enabled=false;
    		Panel3->Enabled=false;
    		Panel5->Enabled=false;
    		Panel1->Enabled=false;
    		Panel6->Enabled=false;
    
    		DBEdit14->Text=DataModule3->Cursos->Fields->FieldByName("FechaIni")->AsDateTime;
    		DBEdit15->Text=DataModule3->Cursos->Fields->FieldByName("FechaFin")->AsDateTime;
    		break;
    
    		case 3:
    		Form14->Caption="Modificacion de Evaluacion";
    		BitBtn17->Caption="Guardar";
    		Panel2->Enabled=true;
    		Panel4->Enabled=true;
    		Panel5->Enabled=true;
    		DBEdit14->Text=DataModule3->Cursos->Fields->FieldByName("FechaIni")->AsDateTime;
    		DBEdit15->Text=DataModule3->Cursos->Fields->FieldByName("FechaFin")->AsDateTime;
    		DataModule3->Evaluacion->Edit();
    		break;
    
    		case 4:
    		Form14->Caption="Baja de Evaluacion";
    		BitBtn17->Caption="Eliminar";
    		Panel5->Enabled=false;
    		Panel2->Enabled=false;
    		Panel4->Enabled=true;
    		DBEdit14->Text=DataModule3->Cursos->Fields->FieldByName("FechaIni")->AsDateTime;
    		DBEdit15->Text=DataModule3->Cursos->Fields->FieldByName("FechaFin")->AsDateTime;
    		break;
    
    	}
    }
    //---------------------------------------------------------------------------
    
    
    
    void __fastcall TForm14::BitBtn7Click(TObject *Sender)
    {
    
    	switch(PageControl1->TabIndex)
    		{
    		case 0:
    		if(OpenPictureDialog1->Execute())
    				{
    		DBImage2->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    		DBImage2->CopyToClipboard();
    		DBImage2->PasteFromClipboard();
    				}
    		break;
    
    				case 1:
    		if(OpenPictureDialog1->Execute())
    				{
    		DBImage3->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    		DBImage3->CopyToClipboard();
    		DBImage3->PasteFromClipboard();
    				}
    		break;
    
    				case 2:
    		if(OpenPictureDialog1->Execute())
    				{
    		DBImage4->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    		DBImage4->CopyToClipboard();
    		DBImage4->PasteFromClipboard();
    				}
    		break;
    
    				case 3:
    		if(OpenPictureDialog1->Execute())
    				{
    		DBImage5->Picture->LoadFromFile(OpenPictureDialog1->FileName);
    		DBImage5->CopyToClipboard();
    		DBImage5->PasteFromClipboard();
    				}
    		break;
    		}
    
    
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn8Click(TObject *Sender)
    {
    
    switch(PageControl1->TabIndex)
    		{
    			case 0:
    				 DBImage2->Picture->LoadFromFile("C:\\Tables\\Blanco.bmp");
    			break;
    
    						case 1:
    				 DBImage3->Picture->LoadFromFile("C:\\Tables\\Blanco.bmp");
    			break;
    
    						case 2:
    				 DBImage4->Picture->LoadFromFile("C:\\Tables\\Blanco.bmp");
    			break;
    
    						case 3:
    				 DBImage5->Picture->LoadFromFile("C:\\Tables\\Blanco.bmp");
    			break;
    
    		}
    
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn9Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
    	{
    	DBEdit10->Text=OpenDialog1->FileName;
    
    	}
    DBEdit10->Text=StringReplace(DBEdit10->Text,"\\","\\\\",TReplaceFlags() << rfReplaceAll);
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn12Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
    	{
    	DBEdit9->Text=OpenDialog1->FileName;
    
    	}
    DBEdit9->Text=StringReplace(DBEdit9->Text,"\\","\\\\",TReplaceFlags() << rfReplaceAll);
    
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn13Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
    	{
    	DBEdit11->Text=OpenDialog1->FileName;
    
    	}
    DBEdit11->Text=StringReplace(DBEdit11->Text,"\\","\\\\",TReplaceFlags() << rfReplaceAll);
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn16Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
    	{
    	DBEdit12->Text=OpenDialog1->FileName;
    
    	}
    DBEdit12->Text=StringReplace(DBEdit12->Text,"\\","\\\\",TReplaceFlags() << rfReplaceAll);
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn18Click(TObject *Sender)
    {
    DataModule3->Evaluacion->Cancel();
    DataModule3->Evaluacion->Close();
    Form14->Close();
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn17Click(TObject *Sender) //this is the button to save the instance of EVALUATION
    {
    if(Tag==1 || Tag==3)
    	{
    	//=============================================================
    AnsiString DniAlum;
    AnsiString Ncompetencia;
    DniAlum=DBEdit7->Text;
    Ncompetencia=DBEdit16->Text;
    
    DataModule3->QueryEjecuciones->Close();
    DataModule3->QueryEjecuciones->SQL->Clear();
    DataModule3->QueryEjecuciones->SQL->Add("SELECT * FROM AlumCom WHERE Num_CompetenciaA='"+Ncompetencia+"' AND Dni_A='"+DniAlum+"'");
    
    
    DataModule3->QueryEjecuciones->Open();
    
    DataModule3->AlumCom->Open();
    DataModule3->AlumCom->IndexName="ICodAlumCom";
    DataModule3->AlumCom->SetKey();
    DataModule3->AlumCom->Fields->FieldByName("CodAlumCom")->AsInteger=DataModule3->QueryEjecuciones->Fields->FieldByName("CodAlumCom")->AsInteger;
    DataModule3->AlumCom->GotoNearest();
    
    
    DataModule3->AlumCom->Edit();
    DataModule3->AlumCom->Fields->FieldByName("Apto")->AsString=ComboBox1->Text;
    DataModule3->AlumCom->Post();
    
    DataModule3->AlumCom->Close();
    DataModule3->QueryEjecuciones->Close();
    //-----------------------------------------------------------------------
    
    	 DataModule3->Evaluacion->Fields->FieldByName("Dni")->AsString=DBEdit7->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Nombre")->AsString=DBEdit2->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Apellidos")->AsString=DBEdit3->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Practicas")->AsString=DBComboBox1->Text;
    	 if(DBEdit13->Text=="")
    		{
             DBEdit13->Text="0";
    		}
    	 DataModule3->Evaluacion->Fields->FieldByName("HorasPracticas")->AsInteger=StrToInt(DBEdit13->Text);
    
    	 DBImage1->CopyToClipboard();
    	 DBImage7->PasteFromClipboard();
    
    	 DataModule3->Evaluacion->Fields->FieldByName("Apto")->AsString=ComboBox1->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Ncurso")->AsString=DBEdit1->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Especialidad")->AsString=DBEdit5->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("PracticasCur")->AsString=DBComboBox2->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("FechaIni")->AsDateTime=DBEdit14->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("FechaFin")->AsDateTime=DBEdit15->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("NombreCur")->AsString=DBEdit4->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Tutor")->AsString=DBEdit6->Text;
    		 if(DBEdit8->Text=="")
    		{
             DBEdit18->Text="0";
    		}
    	 DataModule3->Evaluacion->Fields->FieldByName("Ano")->AsInteger=StrToInt(DBEdit8->Text);
    
    	 DataModule3->Evaluacion->Fields->FieldByName("NumCompetencia")->AsInteger=StrToInt(DBEdit16->Text);
    	 DataModule3->Evaluacion->Fields->FieldByName("NomCompetencia")->AsString=DBEdit18->Text;
    	 DataModule3->Evaluacion->Fields->FieldByName("Horas")->AsInteger=StrToInt(DBEdit17->Text);
    	 DataModule3->Evaluacion->Fields->FieldByName("Objetivo")->AsString=DBMemo1->Text;
    
    
    
    	  DataModule3->Evaluacion->Post();
    	  DataModule3->Evaluacion->Close();
    	  Close();
    	}
    
    else
    	{
    	//=============================================================
    AnsiString DniAlum;
    AnsiString Ncurso;
    AnsiString Ncompe;
    DniAlum=DBEdit7->Text;
    Ncurso=DBEdit1->Text;
    Ncompe=DBEdit16->Text;
     DataModule3->QueryEjecuciones->Close();
    DataModule3->QueryEjecuciones->SQL->Clear();
    DataModule3->QueryEjecuciones->SQL->Add("SELECT * FROM AlumCom WHERE Num_CompetenciaA='"+Ncompe+"' AND Dni_A='"+DniAlum+"'");
    //DataModule3->Query3->SQL->Add("CodigoMod=");
    //DataModule3->Query3->SQL->Add(num1);
    //DataModule3->Query3->SQL->Add(" OR CodigoMod=");
    //DataModule3->Query3->SQL->Add(num2);
    
    DataModule3->QueryEjecuciones->Open();
    DataModule3->AlumCom->Open();
    DataModule3->AlumCom->IndexName="";
    DataModule3->AlumCom->SetKey();
    DataModule3->AlumCom->Fields->FieldByName("CodAlumCom")->AsInteger=DataModule3->QueryEjecuciones->Fields->FieldByName("CodAlumCom")->AsInteger;
    DataModule3->AlumCom->GotoNearest();
    
    
    DataModule3->AlumCom->Edit();
    DataModule3->AlumCom->Fields->FieldByName("Apto")->AsString="";
    DataModule3->AlumCom->Post();
    DataModule3->AlumCom->Close();
    DataModule3->QueryEjecuciones->Close();
     //-----------------------------------------------------------------------
    	DataModule3->Evaluacion->Delete();
    	 DataModule3->Evaluacion->Close();
    	  Close();
        }
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::FormClose(TObject *Sender, TCloseAction &Action)
    {
    DataModule3->Evaluacion->Cancel();
    DataModule3->Evaluacion->Close();
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn10Click(TObject *Sender)
    {
     ShellExecute(NULL,"open",DBEdit10->Text.c_str(), NULL,NULL, SW_SHOW);
    }
    //---------------------------------------------------------------------------
    
    
    
    
    void __fastcall TForm14::BitBtn11Click(TObject *Sender)
    {
     ShellExecute(NULL,"open",DBEdit9->Text.c_str(), NULL,NULL, SW_SHOW);
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn14Click(TObject *Sender)
    {
     ShellExecute(NULL,"open",DBEdit11->Text.c_str(), NULL,NULL, SW_SHOW);
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::BitBtn15Click(TObject *Sender)
    {
     ShellExecute(NULL,"open",DBEdit12->Text.c_str(), NULL,NULL, SW_SHOW);
    }
    //---------------------------------------------------------------------------
    
    
    
    void __fastcall TForm14::DBImage2Click(TObject *Sender)
    {
    
    Timer1->Enabled=true;
    Timer2->Enabled=false;
    
    switch(PageControl1->ActivePageIndex)
    	{
    	case 0:
    DBImage6->Visible=true;
    DBImage6->Picture->Graphic=DBImage2->Picture->Graphic;
    	break;
    
    		case 1:
    DBImage6->Visible=true;
    DBImage6->Picture->Graphic=DBImage3->Picture->Graphic;
    	break;
    		case 2:
    DBImage6->Visible=true;
    DBImage6->Picture->Graphic=DBImage4->Picture->Graphic;
    	break;
    		case 3:
    DBImage6->Visible=true;
    DBImage6->Picture->Graphic=DBImage5->Picture->Graphic;
    	break;
    	}
    
    
    }
    //---------------------------------------------------------------------------
    
    
    
    
    void __fastcall TForm14::Timer1Timer(TObject *Sender)
    {
    if(DBImage6->Top>311)
    {
    
    DBImage6->Top=DBImage6->Top-10;
    }
    
    if(DBImage6->Left>292)
    {
    
    DBImage6->Left=DBImage6->Left-10;
    }
    
    if(DBImage6->Height<407)
    {
    
    DBImage6->Height=DBImage6->Height+6;
    }
    
    if(DBImage6->Width<497)
    {
    
    DBImage6->Width=DBImage6->Width+9;
    }
    
    
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::Timer2Timer(TObject *Sender)
    {
     if(DBImage6->Top<486)
    {
    
    DBImage6->Top=DBImage6->Top+10;
    }
    
    
    if(DBImage6->Left<332)
    {
    
    DBImage6->Left=DBImage6->Left+10;
    }
    
    if(DBImage6->Height>230)
    {
    
    DBImage6->Height=DBImage6->Height-6;
    }
    
    if(DBImage6->Width>224)
    {
    
    DBImage6->Width=DBImage6->Width-9;
    }
    else
    {
    	DBImage6->Visible=false;
    }
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm14::DBImage6Click(TObject *Sender)
    {
    Timer2->Enabled=true;
    Timer1->Enabled=false;
    }
    //---------------------------------------------------------------------------

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    I'm not particularly interested in wading through 1000's of lines of GUI code, especially code with such poor indentation

    What I will suggest however is that you create a simple console application to explore this aspect of the problem.

    Eg.
    Code:
    int main ( ) {
      for ( int i = 0 ; i < 10000 ; i++ ) {
        // invent (or re-use) a filename for an image file
        // load it into the database
      }
    }
    If this fails, you have a really simple code to post, and a really simple code to edit/debug as you explore why it fails.

    When it works, you can compare the logic with your full GUI code to see if there is anything you missed.

    If your GUI code subsequently fails, then it should be fairly certain that it has nothing to do with the image loading.

    Every time you come across some unfamiliar concept, then it is worth investing the time in creating simple programs to explore that concept, just to make sure you understand it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Thank you for all Salem. I learn so much about the posting in a programming forum....despite of your angry tone. Sorry for my mistakes.
    From now I will try to help in this community.


    About my problem. The error not is in the code.
    When I try to save 4 images at same time in a TABLE,if among all these this space is more than 1 mega (more or less).... the error, 'Bitmap Image is not Valid', is triggered.

    I will try to find any solution.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Tell me, was there sufficient information in that huge code dump for me to be able to copy/paste into an EMPTY project and reproduce your problem?

    If not, then there was little point in me spending time wading through it.

    But if you still want to create huge programs which "surprise" don't work the first time you run them, only to post sections of them on forums, and then blame people who try to help you for your failure, then good luck with that.

    Very few people are willing to spend several HOURS on a single post (which is what your massive code dump full of irrelevant detail would have taken).

    Short FOCUSED test programs exploring the key problem (for you) get the most interest (from us).
    50 to 100 lines of nicely indented code is very easy to analyse, whereas your 100's of lines of chaos is not.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,422
    FieldByName("Ano")-> you made a funny... con " " mejor tio creo hehe!
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmap Image In C
    By snayyer in forum C Programming
    Replies: 9
    Last Post: 06-20-2011, 10:16 AM
  2. get bitmap from image in website.
    By sgh in forum C# Programming
    Replies: 3
    Last Post: 03-23-2009, 09:34 PM
  3. how to convert a bitmap image to a jpg image file using C++?
    By nomer in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2006, 07:40 PM
  4. Reading a bitmap image
    By usamaalam in forum C Programming
    Replies: 19
    Last Post: 03-06-2004, 05:13 AM
  5. Display a bitmap image
    By MysticMizra in forum Windows Programming
    Replies: 7
    Last Post: 10-21-2002, 03:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21