Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Image in database
Image in database [message #31932] Fri, 08 April 2011 15:39 Go to next message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
Hi,

Could somebody give me an example on how to put an image in a database, please ?

I suppose that I must use a BLOB for that ? I have an image class, I can show the image in a StaticImage control, but I don't succeed in memorizing it in a database...
Re: Image in database [message #31934 is a reply to message #31932] Fri, 08 April 2011 21:10 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi jibe,

I use a helper class in one of my apps.

It can be used with the following SQL schema description:
// ========================================
//          IMAGES
// ========================================
TABLE_(IMAGES)
	INT_	(IMG_ID) PRIMARY_KEY AUTO_INCREMENT
	INT_	(IMG_HASH)  INDEX
	INT_    (IMG_REFCOUNT) SQLDEFAULT(0) // reference counter
	LONGRAW_(IMG_DATA)
END_TABLE


NB: The hash and REFCOUNT are not used yet, they are intended for future devs.

The idea is to have all images in one table and manage references to these images in the other tables:
TABLE_(CLUBS)
	INT_    (CLUB_ID) PRIMARY_KEY AUTO_INCREMENT
	STRING_ (CLUB_NUMBER, 10)
	STRING_ (CLUB_NOM, 60)
	STRING_ (CLUB_ALIAS, 10)
	STRING_ (CLUB_ADRESSE, 250)
	STRING_ (CLUB_VILLE, 30)
	INT_    (CLUB_CODE_POSTAL)
	STRING_ (CLUB_NUM_TEL, 20)
	INT_    (CLUB_REF_LIGUE) REFERENCES(LIGUE)
	INT_    (CLUB_LOGO_SMALL_IMGREF)  SQLDEFAULT(-1)     **** IMAGE ****
	INT_    (CLUB_LOGO_BIG_IMGREF)    SQLDEFAULT(-1)     **** IMAGE ****
	STRING_ (CLUB_MAIL, 50)
END_TABLE


In order to use it you finally need to do something like this:

clubsData.CLUB_LOGO_BIG_IMGREF = ImageMgr::addImage( clubCtrls.imgPresentation.GetImage() );

or

clubCtrls.imgPresentation.SetData( ImageMgr::getImageString( clubsData.CLUB_LOGO_SMALL_IMGREF ) );



Hope this will be useful for you
Re: Image in database [message #31950 is a reply to message #31934] Sun, 10 April 2011 20:54 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

My Image Ctrl

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Image in database [message #31951 is a reply to message #31950] Sun, 10 April 2011 20:55 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

And Test program for EditImage

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Image in database [message #31952 is a reply to message #31932] Mon, 11 April 2011 09:10 Go to previous messageGo to next message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
Hi,

Thanks to the 2 of you Smile

I'll see that and let you know...
Re: Image in database [message #31955 is a reply to message #31932] Mon, 11 April 2011 11:16 Go to previous messageGo to next message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
It works !

I did it a simplest way than Didier : why do you put your images in a different table ? Is it better in all cases - and if so why ? - or it was just for your application ?

@sergeynikitin : Thanks for your very interresting sample, but my goal was to save the image in a database, not in a file Wink Anyway, I think that I'll learn a lot with your code and I'm happy that you share it Smile
Re: Image in database [message #31979 is a reply to message #31955] Wed, 13 April 2011 23:08 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Jibe,

There are two reasons why I put all images in one table:
* keeping them out of the other tables keeps from having to load them when manipulating database records and so speeds up things
* The same image can be used by more than one record.

NB: In my code all the images are stored in jpg format in order to gain disk space but if you are trying to save images with trasnparency you have to store them in gif format
Re: Image in database [message #31983 is a reply to message #31955] Thu, 14 April 2011 08:46 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

jibe wrote on Mon, 11 April 2011 13:16

It works !



@sergeynikitin : Thanks for your very interresting sample, but my goal was to save the image in a database, not in a file Wink Anyway, I think that I'll learn a lot with your code and I'm happy that you share it Smile


Put EditImage in folder under MyApps

EditImageTest contain example to store image in DataBase (with use EditImage control to view and add image).
You can use EditImage as Ctrl in Layout Designer.

EditImageTest contain commented example of storing images to and loading images from BLOB field of database.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Image in database [message #31994 is a reply to message #31979] Fri, 15 April 2011 09:28 Go to previous message
jibe is currently offline  jibe
Messages: 294
Registered: February 2007
Location: France
Experienced Member
Hi,

Didier wrote on Wed, 13 April 2011 23:08

Hi Jibe,

There are two reasons why I put all images in one table:
* keeping them out of the other tables keeps from having to load them when manipulating database records and so speeds up things
* The same image can be used by more than one record.

Yes, you're right : it's often better to do this way...

Didier wrote on Wed, 13 April 2011 23:08

NB: In my code all the images are stored in jpg format in order to gain disk space but if you are trying to save images with trasnparency you have to store them in gif format

Yes, of course ! Gif or PNG Wink

sergeynikitin wrote on Thu, 14 April 2011 08:46

EditImageTest contain example to store image in DataBase (with use EditImage control to view and add image).

Sorry, I did not see that Embarassed I'll look more attentively and test : it looks very interresting Smile
Previous Topic: Is this really a GUI RAD?
Next Topic: Tell me more about U++ please.
Goto Forum:
  


Current Time: Mon May 06 10:18:38 CEST 2024

Total time taken to generate the page: 0.03580 seconds