Click here to Skip to main content
15,900,108 members
Articles / Programming Languages / C#

Creating a poster frame from your photos

Rate me:
Please Sign up or sign in to vote.
4.80/5 (2 votes)
21 Apr 2013CPOL2 min read 13.7K   4   1
A cool and funny application to make frames from a set of your best pictures

Introduction 

A picture is worth a thousand words! So imagine a frame on your wall arranging a matrix of hundreds of you best pictures?!? Or many frames arranging different photo albuns?!? Cool isnt it?
We know, we know, soon or later someone will comment below here why to do this, there are some programs over the web which do the same and bla bla bla...  Well I will answer, we like to program, it is our hobby : ) 

More considerations... It is only a prototype, so for sure there may have issues and sure many features that can be incorporated, so... do not loose much time trying to scratch issues, because surely you will find!!! : )   

Background 

Once we have created a program to make a frame here at home which is about 40x25 inches and displays about 400 of our best pictures and it became a fever on friends asking for we have decided to publish it.  


Our poster at home with > 400's pictures printed in dull paper
and framed with anti reflective glass 

Using the code 

The code is pretty simple, it loads a set of images redimension them and rearrange in a new bigger image, feel free to modify it according to your needings.

Yes, it can be smarter and fill the empty spaces in the end of the final image, calculate heights and work resizing vertical pictures preserving ratio etc etc etc.  

C#
/// First of all input a folder and get its image files 

string[] files = Directory.GetFiles(strFolder);
int count = 0;
foreach (string file in files)
    {
    string lowerfile = file.ToLower();
    if (lowerfile.Contains(".gif") || lowerfile.Contains(".png") || lowerfile.Contains(".jpg") || lowerfile.Contains(".jpeg"))
        {
        count++;
        }
    }  
ImageIt(count, files); 
C#
/// The rearranging function
private void ImageIt(int count, string[] files)
    {
    // redimensioned image width
    double w = 64.0 * 4.0;
    // redimensioned image height 	 
    double h = 48.0 * 4.0;
    // ratio
    double f = w / h;
    // rows quantity
    int iw = (int)Math.Sqrt((double)count / f);
    // columns quantity
    int ih = (int)((double)iw * f);
    // create a bitmap container with borders extra space
    Bitmap newb = new Bitmap(iw * (int)w + (iw + 1) * 5, ih * (int)h + (ih + 1) * 5);
    Graphics g = Graphics.FromImage(newb);
    g.Clear(Color.Black);
    Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
    int i = 0, j = 0, iCount = 0;
    foreach (string file in files)
        {
        string lowerfile = file.ToLower();
        if (lowerfile.Contains(".gif") || lowerfile.Contains(".png") || lowerfile.Contains(".jpg") || lowerfile.Contains(".jpeg"))
            {
            try
                 {
 	         Bitmap bmp = new Bitmap(lowerfile);
                 Image img = Image.FromFile(lowerfile);
                 Image thumb = img.GetThumbnailImage((int)w, (int)h, myCallback, IntPtr.Zero);
                 g.DrawImage(thumb, new Point(5 + (int)w * i + 5 * i, 5 + (int)h * j + 5 * j));
                 g.Flush();
                 i++;
                 iCount++;
                 // reset counter
                 if (i % iw == 0) { j++; i = 0; }
 	         // stop in maximum images defined
                 if (iCount == count) break;
 	         }
            catch (Exception ex)
  	         {
                 MessageBox.Show(ex.Message);
 	         }
            }
        }
    } 
C#
/// callback for GetThumbnailImage
public static bool ThumbnailCallback()
    {
    return false;
    }    

 

 

Points of Interest

It is incredible the quantity of friends who likes to have their own poster, so this is why we have decided to make it public. Enjoy!

History

It is in a very raw version, 1.0, maybe in the future we make some improvements to the tool. Any ideia for feature is very welcome.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Brazil Brazil
"A well written code is self explanatory" - Anonymous Programmer
"The number of meetings is directly proportional to the bad management" - Another Anonymous Programmer
Founder @TIHUNTER.COM.BR
Linkedin Profile

Comments and Discussions

 
SuggestionAdd video Pin
Mai Chấn Duy11-Oct-15 5:38
Mai Chấn Duy11-Oct-15 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.