I was thinking about how would a paint software works. Firstly I thought that it might not use any database but when I started thinking about the undo function I realized that it might be that the data is somehow stored in the database. Can anyone please help me out by telling me how the images are stored in a normal paint program(say MS-PAINT of Windows).
Images aren't usually stored in a database (assuming you mean something like an SQL database) as the format isn't suited to image data.
Images are usually stored as files in folders - just as Word, Excel, OpenOffice documents are.
When you manipulate the data the program keeps a record of your changes in memory (usually) so that you can undo and redo modifications. Sometimes when you save the file the undo stack is cleared so you can only undo to last version on the hard drive.
Some file formats allow revision information to be stored in the file itself - but this isn't usually the case for images. What you have on disk is the only version of the file. If you want to keep a revision history then you need to either keep manual backups or store the file in a version control system, unless the underlying file system supports this natively. An example of the latter is ZFS under OpenSolaris, which allow for a "look back in time" functionality with Time Slider - http://java.dzone.com/news/killer-feature-opensolaris-200. Unfortunately, Solaris is heading in a different direction these days.
You could look at the implementations of the undo functionality in some open source programs. Perhaps the The GIMP or Version 3.36 or earlier of Paint.NET (when it was still open source) might provide you with some inspiration. However, the Command and Memento design patterns are commonly cited as good ways to implement the undo/redo functionality.
CSLA for .NET serializes a copy of the object that you wish to save undo-history on and stores it in a stack of undo's... so you can keep popping back through history (Might be a little off on how it's stored, but fairly confident in the overall method)...
No database needed, infact, it's overkill to have a database to save "undo" information. Just find a way to store "instances" of your data (paint info) and be able to recall them.
If I name the filesystem as non-relational database - then probably - yes, else - depends what and how do you painting and how do your paintings organized.