#windows-7 #3d #thumbnails
#windows-7 #3D #миниатюры
Вопрос:
Я хочу программно создать эскиз из папки с изображениями, который был бы похож на стиль папки с изображениями Windows 7, как на картинке, которую я загрузил здесь. У меня есть процедура, которая будет добавлять изображения друг на друга и поворачивать их по оси x, но я думаю, что мне нужно немного поворота Y или что-то в этом роде, чтобы сделать эту иллюзию полной. На самом деле я сделал это с помощью Windows7APICodePack с помощью методов создания эскизов, но, похоже, это вынуждает вас использовать Explorer в режиме больших значков. Я не хочу, чтобы это зависело от проводника. Я также не хочу использовать WPF (Viewport3D). Вот как я хочу, чтобы это выглядело: FinalImage http://www.chuckcondron.com/folderexample.JPG
Вот что я сделал до сих пор: StitchedImageThumb http://www.chuckcondron.com/stitchedImageThumb.jpg
Как вы можете видеть, моя попытка не так хороша, и фотографии не выходят из папки кремового цвета (на самом деле можно было бы использовать и фактическую папку pic, но не уверен, как это сделать).
текущий код (c #)
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<Bitmap> images = new List<Bitmap>();
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 > 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;
}
}
}
Комментарии:
1. Язык? (Я так понимаю VB.NET или C #) Текущий код?
2. обновлено с использованием текущего кода c # / .net