-
20-08-2019 - |
题
我需要转换位图图像,并将其 4 个角点从一个位置移动到另一个位置。
任何可以在 Windows 上运行的代码,最好是 C#/VB.NET,甚至可以帮助如何使用可编写脚本的程序,例如 画图网 或者 Photoshop 会被接受。Java 高级成像 API 听起来充满希望。
我需要它作为屏幕截图操纵系统,它可以让你获得这样的效果:
(来源: Wholetomato.com)
其他提示
声明:我在Atalasoft工作
如果你愿意去商业,DotImage照片可以用QuadrilateralWarpCommand做到这一点。样品C#代码
// Load an image.
AtalaImage image = new AtalaImage("test-image.jpg");
// Prepare the warp positions.
Point bottomLeft = new Point(100, image.Height - 80);
Point topLeft = new Point(130, 45);
Point topRight = new Point(image.Width - 60, 140);
Point bottomRight = new Point(image.Width - 20, image.Height);
// Warp the image.
QuadrilateralWarpCommand cmd = new QuadrilateralWarpCommand(bottomLeft,
topLeft, topRight, bottomRight, InterpolationMode.BiLinear, Color.White);
AtalaImage result = cmd.Apply(image).Image;
更容易比模拟的立体歪曲使用图像处理,则可以使用OpenGL或DirectX(XNA)实际执行立体显示。
渲染与您的图像作为纹理映射的简单四边形。设置场景,渲染到一个缓冲区,你有你的形象。
更新原来,XNA是一个荒谬的库(对制作游戏,没有别的,打哈欠减速)。托管DirectX需要一个大脑脑叶手术。 OpenGL是简单易用,但缺乏图像加载代码。这给我们留下了WPF:
替代文字http://praeclarum.org/so/persp.png
图片可以通过迫使WPF到抗混叠模式来提高(为什么啊,为什么微软你这么短视?),而不是利用航空玻璃,强行将取消对所有屏幕截图1像素的黑色边框(或一个1个像素边界)。
(对不起,此码的长度,但WPF是一个健谈的API。)
public partial class Window1 : Window {
const float ANGLE = 30;
const float WIDTH = 8;
public Window1() {
InitializeComponent();
var group = new Model3DGroup();
group.Children.Add(Create3DImage(@"C:\Users\fak\Pictures\so2.png"));
group.Children.Add(new AmbientLight(Colors.White));
ModelVisual3D visual = new ModelVisual3D();
visual.Content = group;
viewport.Children.Add(visual);
}
private GeometryModel3D Create3DImage(string imgFilename) {
var image = LoadImage(imgFilename);
var mesh = new MeshGeometry3D();
var height = (WIDTH * image.PixelHeight) / image.PixelWidth;
var w2 = WIDTH / 2.0;
var h2 = height / 2.0;
mesh.Positions.Add(new Point3D(-w2, -h2, 0));
mesh.Positions.Add(new Point3D(w2, -h2, 0));
mesh.Positions.Add(new Point3D(w2, h2, 0));
mesh.Positions.Add(new Point3D(-w2, h2, 0));
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(3);
mesh.TextureCoordinates.Add(new Point(0, 1)); // 0, 0
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(1, 0));
mesh.TextureCoordinates.Add(new Point(0, 0));
var mat = new DiffuseMaterial(new ImageBrush(image));
mat.AmbientColor = Colors.White;
var geometry = new GeometryModel3D();
geometry.Geometry = mesh;
geometry.Material = mat;
geometry.BackMaterial = mat;
geometry.Transform = new RotateTransform3D(
new AxisAngleRotation3D(new Vector3D(0,1,0), ANGLE),
new Point3D(0, 0, 0));
return geometry;
}
public static BitmapSource LoadImage(string filename) {
return BitmapDecoder.Create(new Uri(filename, UriKind.RelativeOrAbsolute),
BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
}
}
和所需XAML:
<Window x:Class="Persp.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Perspective Window" Height="480" Width="640">
<Grid>
<Viewport3D x:Name="viewport">
<Viewport3D.Resources>
</Viewport3D.Resources>
<Viewport3D.Camera>
<PerspectiveCamera x:Name="cam"
FarPlaneDistance="100"
LookDirection="0,0,-1"
UpDirection="0,1,0"
NearPlaneDistance="1"
Position="0,0,10"
FieldOfView="60" />
</Viewport3D.Camera>
</Viewport3D>
</Grid>
</Window>
不隶属于 StackOverflow