April 4th, 2005

I am trying to create an application that creates a mosaic of all of my Australia pictures, here is my first try -




Here is the code for it so far -

            Image i,v,t,thumb;
            //Bitmap b;
            Graphics g,rg;
            i=Image.FromFile(((imageFile)lstImages.Items[0]).FI.FullName);
            double scale=i.Width/((int)nudWidth.Value);

            v=new Bitmap(((int)nudWidth.Value)*((int)nudAcross.Value),
              (lstImages.Items.Count/((int)nudAcross.Value))*(int)(i.Height/scale));

            int x=0;
            int y=0;

            foreach(imageFile @if in lstImages.Items)
            {
                i=Image.FromFile(@if.FI.FullName);
                if(i.Height>i.Width) i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                thumb=new Bitmap((int)(i.Width/scale),(int)(i.Height/scale));
                rg=Graphics.FromImage(thumb);
                rg.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                rg.DrawImage(i,new Rectangle(0,0,(int)(i.Width/scale),(int)(i.Height/scale)),
                    new Rectangle(0,0,i.Width,i.Height),GraphicsUnit.Pixel);

                rg.Dispose();

                g=Graphics.FromImage(v);
                g.DrawImageUnscaled(thumb,x*(int)(i.Width/scale),y*(int)(i.Height/scale));
                g.Dispose();
                x++;
                if(x-1==((int)nudAcross.Value))
                {
                    x=0; y++;
                }
            }

            v.Save(txtOutput.Text,System.Drawing.Imaging.ImageFormat.Jpeg);