Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate Windows 7 Image Folder 3d Thumbnail
    text
    copied!<p>I want to programmatically create a thumbnail from a folder of images, that would look similar to the Windows 7 images folder style like the pic I uploaded here. I have a routine that will add images on top of each other, and rotating them in the x-axis, but I think I need some Y rotation or something to make this illusion complete. I have actually done this with the Windows7APICodePack with the thumbnail methods there, but it seems to force you to have Explorer in the Large Icons mode. I do not want this to depend on Explorer. Nor do I want to use WPF (ViewPort3d). Here is what I want it to look like: <a href="http://www.chuckcondron.com/folderexample.JPG" rel="nofollow noreferrer">FinalImage http://www.chuckcondron.com/folderexample.JPG</a></p> <p>Here is what I have done so far: <a href="http://www.chuckcondron.com/stitchedImageThumb.jpg" rel="nofollow noreferrer">StitchedImageThumb http://www.chuckcondron.com/stitchedImageThumb.jpg</a></p> <p>As you can see my attempt is not that pretty, nor do the pics come out of the cream color folder (really could use the actual folder pic as well, but not sure how to do that).</p> <p>current code (c#)</p> <pre><code>using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; namespace ThumbnailCreator { public partial class Form1: Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //get all the files in a directory string[] files = Directory.GetFiles(@"C:\MyImages"); //combine them into one image Bitmap stitchedImage = Combine(files); if(File.Exists("stitchedImage.jpg")) File.Delete("stitchedImage.jpg"); //save the new image stitchedImage.Save(@"stitchedImage.jpg", ImageFormat.Jpeg); if (File.Exists("stitchedImage.jpg")) { FileStream s = File.Open("stitchedImage.jpg", FileMode.Open); Image temp = Image.FromStream(s); s.Close(); pictureBox1.Image = temp; } CreateThumb(@"stitchedImage.jpg", @"stitchedImageThumb.jpg"); } public Bitmap Combine(string[] files) { //read all images into memory List&lt;Bitmap&gt; images = new List&lt;Bitmap&gt;(); Bitmap finalImage = null; try { int width = 0; int height = 0; int rotate = 7; foreach (string image in files) { //create a Bitmap from the file and add it to the list Bitmap bitmap = new Bitmap(image); bitmap = RotateImage(bitmap, rotate); //update the size of the final bitmap //width += bitmap.Width; width = 2500; //height = bitmap.Height &gt; height ? bitmap.Height : height; height = 1000; images.Add(bitmap); rotate += 5; } //create a bitmap to hold the combined image finalImage = new Bitmap(width, height); //get a graphics object from the image so we can draw on it using (Graphics g = Graphics.FromImage(finalImage)) { //set background color g.Clear(Color.Goldenrod); //go through each image and draw it on the final image ImageAttributes ia = new ImageAttributes(); ColorMatrix cm = new ColorMatrix(); cm.Matrix33 = 0.75f; ia.SetColorMatrix(cm); foreach (Bitmap image in images) { Image rotatedImage = new Bitmap(image); g.DrawImage(rotatedImage, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, ia); } } return finalImage; } catch (Exception ex) { if (finalImage != null) finalImage.Dispose(); throw ex; } finally { //clean up memory foreach (System.Drawing.Bitmap image in images) { image.Dispose(); } } } public void CreateThumb(string source, string destination) { Image imgThumb = null; try { Image image = null; // Check if image exists image = Image.FromFile(source); if (image != null) { imgThumb = image.GetThumbnailImage(100, 100, null, new IntPtr()); imgThumb.Save(destination); image.Dispose(); } } catch { MessageBox.Show("An error occured"); } if (File.Exists(destination)) { FileStream s = File.Open(destination, FileMode.Open); Image temp = Image.FromStream(s); s.Close(); pictureBox2.Image = temp; } } private Bitmap RotateImage(Bitmap inputImg, double degreeAngle) { //Corners of the image PointF[] rotationPoints = { new PointF(0, 0), new PointF(inputImg.Width, 0), new PointF(0, inputImg.Height), new PointF(inputImg.Width, inputImg.Height)}; //Rotate the corners PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle); //Get the new bounds given from the rotation of the corners //(avoid clipping of the image) Rectangle bounds = PointMath.GetBounds(rotationPoints); //An empy bitmap to draw the rotated image Bitmap rotatedBitmap = new Bitmap(bounds.Width *2, bounds.Height *2); using (Graphics g = Graphics.FromImage(rotatedBitmap)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; //Transformation matrix Matrix m = new Matrix(); m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f)); m.Translate(-bounds.Left, -bounds.Top, MatrixOrder.Append); //shift to compensate for the rotation g.Transform = m; g.DrawImage(inputImg, 0, 0); } return rotatedBitmap; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload