我有一种情况需要调整大量图像的大小.这些图像当前存储在文件系统上的.jpg文件中,但我希望稍后在项目中将byte []存储在内存中.源图像大小是可变的,但输出应该是3种不同的预定大小.应保留宽高比,用白色空间填充原始图像(即,将调整非常高的图像以适应方形目标图像大小,左侧和右侧具有大的白色区域).
我最初构建了面向.NET 2.0的项目,并使用System.Drawing类来执行加载/调整大小/保存.相关代码包括:
original = Image.FromFile(inputFile); //NOTE: Reused for each of the 3 target sizes
Bitmap resized = new Bitmap(size, size);
//Draw the image to a new image of the intended size
Graphics g = Graphics.FromImage(resized);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.Clear(Color.White);
g.DrawImage(original, center - width / 2f, center - height / 2f, width, height);
g.Dispose();
//Save the new image to the output path
resized.Save(outputFile, ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
我想将此项目移植到.NET 3.5,因此尝试使用System.Windows.Media类来执行相同的功能.我得到了它,但性能很糟糕; 每张图像的处理时间约为50倍.绝大部分时间都花在加载图像上.相关代码包括:
BitmapImage original = new BitmapImage(); //Again, reused for each of the 3 …Run Code Online (Sandbox Code Playgroud) 我有几张桌子,例如:
我希望能够在我的Product对象上包含ManufacturerName(而不必在我只需要名称时加载整个Manufacturer行).我的ProductMap看起来像......
Table("Product");
Id(x => x.Id, "Id");
Map(x => x.ProductName, "ProductName");
Map(x => x.ManufacturerId, "ManufacturerId");
References(x => x.Manufacturer, "ManufacturerId");
Run Code Online (Sandbox Code Playgroud)
我需要添加什么来填充Product对象上的ManufacturerName属性?我相信我需要进行某种Join()调用,但是我无法弄清楚如何使用所有相关参数来编写它.它需要将当前表(Product)连接到Manufacturer表,在Product.ManufacturerId = Manufacturer.Id上,并获取Manufacturer.Name列,在对象上填充ManufacturerName属性.
对不起,模糊的主题标题; 很难简洁地描述我的问题.
我收集了大量的对象(几千个),定义为......
public class Item
{
public int ID;
public float A;
public float B;
public float C;
public float D;
public float E;
public float F;
public float G;
}
Run Code Online (Sandbox Code Playgroud)
如果我为这些浮点字段中的每一个赋予了乘数,那么找到我的大集合中哪个项目中最大的那些浮点数乘以它们的乘数的最快方法是什么.
例如,我现在有类似......
public Item FindLargest(float aMult, float bMult, float cMult, float dMult, float eMult, float fMult, float gMult)
{
Item largest = null;
float largestTotal = 0f;
foreach(Item item in ItemsCollection)
{
float total = item.A * aMult +
item.B * bMult +
item.C * cMult +
item.D …Run Code Online (Sandbox Code Playgroud)