问题已回答。有关更多信息,请参阅本文末尾的编辑#4。添加剂混合的绘图图像
我们目前正在研发一款相当不错的游戏制作引擎。我正在研究动画创作者,并想知道是否可以使用添加混合来绘制图像。
让我解释一下。
我们使用C#的System.Drawing库,并使用Windows窗体。目前,用户能够通过导入带框的动画图像(包含动画的每个帧的图像)来创建他的动画,并且用户能够将这些框架拖放到他想要的任何地方。
实际的问题是,我们无法弄清楚如何绘制一个框架与添加剂混合。
下面是添加剂混合的例子,如果你不太明白。我不会责怪你,我很难用英文写作。
我们使用以下方法在Panel上或直接在窗体上绘图。例如,这里是为地图编辑器绘制平铺地图的代码。由于AnimationManager代码乱七八糟,这个例子会更清晰。
using (Graphics g = Graphics.FromImage(MapBuffer as Image))
using (Brush brush = new SolidBrush(Color.White))
using (Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0), 1))
{
g.FillRectangle(brush, new Rectangle(new Point(0, 0), new Size(CurrentMap.MapSize.Width * TileSize, CurrentMap.MapSize.Height * TileSize)));
Tile tile = CurrentMap.Tiles[l, x, y];
if (tile.Background != null) g.DrawImage(tile.Background, new Point(tile.X * TileSize, tile.Y * TileSize));
g.DrawRectangle(pen, x * TileSize, y * TileSize, TileSize, TileSize);
}
有没有用添加剂绘图如果是绘制图像的一个可行的办法,我会永远感激,如果有人可以点我如何。谢谢。
EDIT#1:
对于绘制图像,我们用的是彩色矩阵来设置这样的色调和ALPH(不透明度):
ColorMatrix matrix = new ColorMatrix
(
new Single[][]
{
new Single[] {r, 0, 0, 0, 0},
new Single[] {0, g, 0, 0, 0},
new Single[] {0, 0, b, 0, 0},
new Single[] {0, 0, 0, a, 0},
new Single[] {0, 0, 0, 0, 1}
}
);
也许彩色矩阵可用于添加剂混合?
编辑#2:
刚刚发现this文章马赫什昌。
在进一步浏览之后,即使色彩转换可以完成很多工作,也可能无法使用色彩矩阵。 如果找到解决方案,我会回答我自己的问题。
谢谢你的帮助。
编辑#3:
XNA有很多关于混合文档here的。我找到了用于在图像的每个像素上完成叠加混合的公式。
PixelColor =(源* [1,1,1,1])+(目的地* [1,1,1,1])
也许有在当前上下文中使用此公式的一个方法是什么? 我将在下次编辑时启动50条赏金,我们确实需要这个工作。
再次感谢您的时间。
编辑#4
由于轴突,现在的问题就解决了。使用XNA和Spritebatch,你可以做到添加剂调合这样做:
首先创建的GraphicsDevice和SpriteBatch
// In the following example, we want to draw inside a Panel called PN_Canvas.
// If you want to draw directly on the form, simply use "this" if you
// write the following code in your form class
PresentationParameters pp = new PresentationParameters();
// Replace PN_Canvas with the control to be drawn on
pp.BackBufferHeight = PN_Canvas.Height;
pp.BackBufferWidth = PN_Canvas.Width;
pp.DeviceWindowHandle = PN_Canvas.Handle;
pp.IsFullScreen = false;
device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, pp);
batch = new SpriteBatch(device);
然后,当它的时间上绘制控件或形式(与OnPaint事件例如),则可以使用下面的代码块
// You should always clear the GraphicsDevice first
device.Clear(Microsoft.Xna.Framework.Color.Black);
// Note the last parameter of Begin method
batch.Begin(SpriteSortMode.BackToFront, BlendState.Additive);
batch.draw(/* Things you want to draw, positions and other infos */);
batch.End();
// The Present method will draw buffer onto control or form
device.Present();
我不确定这是可能的直接向上的winforms,而不诉诸于自己的像素值操纵。将使用WPF托管组件作为图纸是一个选项吗?WPF有能力更容易地设置混合模式。 – Dervall
@Dervall我们越搜索越多,我们开始认为使用WPF托管组件是一个非常好的主意。也许没有直接使用Winforms使用逐像素算法的解决方案。或者,也许有人会想出一些奇迹? –
[.DrawImage with opacity?]的可能重复?(http://stackoverflow.com/questions/5519956/drawimage-with-opacity) –