Rank: Newbie
Groups: Guest
Joined: 10/2/2015(UTC) Posts: 5
|
Eugene, Thanks for your feedback. This code performs better than my version, and I can control the resize mode now. However, the smoothness problem still exists. Here are the videos I generated with System.Drawing and GraphicsMill Library 1. Video with System.Drawing: (smoother)http://vhtbucket-dev.s3....a6-9499-94e12280acbf.mp42. Video with GraphicsMill Library: (shaky)http://vhtbucket-dev.s3....95-98e6-0049f292c9d3.mp4As I mentioned before, I generate the image sequence based on the individual image. Each frame describes a small and simple movement of each image, like zoom in/zoom out. Because each video frame requires a precise movement change, so I assume this is related to the RectangleF class. With the System.Drawing Library, I was using the float variable to specify the source Rectangle X, Y, Width, and Height. However, with the GraphicsMill library, I cannot crop the rectangle with the float variable. Let me know if you need any other information, and thanks again. Code with System.Drawing:Code:
public void DrawToFile(string filePath, int width, int height)
{
var dstframeRect = new Rectangle(0, 0, width, height);
using (var frameBmp = new Bitmap(width, height))
{
using (var gFrame = Graphics.FromImage(frameBmp))
{
gFrame.Clear(Color.Transparent);
gFrame.CompositingQuality = CompositingQuality.HighQuality;
gFrame.CompositingMode = CompositingMode.SourceOver;
gFrame.InterpolationMode = InterpolationMode.HighQualityBicubic;
gFrame.SmoothingMode = SmoothingMode.HighQuality;
gFrame.PixelOffsetMode = PixelOffsetMode.HighQuality;
foreach (var part in Parts)
{
using (var stream = new MemoryStream(part.Scene.Bytes))
{
using (var sourceImage = new Bitmap(stream))
{
using (var imageAttributes = GetImageAttributesWithAlpha(part.Alpha))
{
// part.Rectangle is RectangleF class and contains source floating point rectangle information
gFrame.DrawImage(sourceImage,
dstframeRect,
part.Rectangle.X,
part.Rectangle.Y,
part.Rectangle.Width,
part.Rectangle.Height,
GraphicsUnit.Pixel,
imageAttributes,
null);
}
}
}
}
}
frameBmp.Save(filePath, ImageFormat.Jpeg);
}
}
Code with GraphicsMill Library:Code:
public void DrawToFile(string filePath, int width, int height)
{
using (var frameBmp = new Aurigma.GraphicsMill.Bitmap(width, height, PixelFormat.Format32bppArgb))
{
frameBmp.Fill(RgbColor.Transparent);
foreach (var part in Parts)
{
var srcRectF = new RectangleF(part.Rectangle.X,
part.Rectangle.Y,
part.Rectangle.Width,
part.Rectangle.Height);
// I need to convert to Rectangle here to use Bitmap.Transforms.Crop, and thus the X, Y, Width, Height become int!
var srcRect = Rectangle.Round(srcRectF);
using (var stream = new MemoryStream(part.Scene.Bytes))
{
using (var srcBitmap = new Aurigma.GraphicsMill.Bitmap(stream))
{
srcBitmap.Transforms.Crop(srcRect);
srcBitmap.Transforms.Resize(width, height, ResizeInterpolationMode.High, ResizeMode.Resize);
frameBmp.Draw(srcBitmap, 0, 0, CombineMode.Alpha, part.Alpha);
}
}
}
frameBmp.Save(filePath, new JpegSettings(95));
}
}
If you are interested to see how the video frames look like, I have uploaded them to Dropbox. 1. System.Drawing image sequence:https://www.dropbox.com/...ZpBeD6Mp_Nb6MoeEtJa?dl=02. GraphicsMill Library image sequence:https://www.dropbox.com/...MClJbgwwHz5IQVpDIBa?dl=0Edited by user Tuesday, December 17, 2019 2:55:44 PM(UTC)
| Reason: Not specified
|