VectorDraw Developer Framework常见问题整理(七十):如何将图像映射到绘图单位

VectorDraw Framework使用vdPolyFace或vdGroundSurface对象的MappedImages属性导出了将图像映射到这些对象的能力。这方面的例子可以在我们的AddEntities示例中找到。

VectorDraw Framework使用vdPolyFace或vdGroundSurface对象的MappedImages属性导出了将图像映射到这些对象的能力。这方面的例子可以在我们的AddEntities示例中找到。
如果你想在你的绘图上映射一个单一的图像,你可以使用下面的示例代码。

假设我们有一个名称为 “myimage.jpg “的图像
同时我们有2个像素坐标系中的点,相对于图像的左上角

例子
    P1_pixel_x , P1_pixel_y

    P2_pixel_x , P2_pixel_y

现在,我们有了一个要映射图像的图纸

vdDocument doc;//already defined VectorDraw Document object。//为选中的像素点构造gPoints gPoint imgp1 = new gPoint(P1_pixel_x , P1_pixel_y,0);gPoint imgp2 = new gPoint(P2_pixel_x, P2_pixel_y,0);//将imagedefinition添加到绘图中vdImageDef imagedef = doc.Images.Add("myimage.jpg" );double Aspect =(double) imagedef .Height / (double)imagedef .Width;//width,所选图像的高度(以像素为单位)//创建一个矩阵,将图像的像素坐标转换为 Unint 宽度矩阵矩阵 pixeltoworld = new Matrix();pixeltoworld.ScaleMatrix(1.0 / magedef .Width, -Aspect /imagedef .Height, 1.0d);pixeltoworld.TranslateMatrix(0.0, Aspect, 0.0);//将像素坐标转换为单位世界坐标imgp1 = pixeltoworld.Transform(imgp1);imgp2 = pixeltoworld.Transform(imgp2);vector offsrc = new Vector(imgp2 - imgp1);//源向量Vector offdst =new Vector(P2_world -P1_world );//目标向量double scale = offdst.Length / offsrc.Length;//计算映射图像的最终变换矩阵Matrix m2 = new Matrix();m2.TranslateMatrix(imgp1 * -1);m2.ScaleMatrix(scale, scale, 1.0);m2.RotateZMatrix(offdst.Angle2DDirection() - offsrc.Angle2DDirection());m2.TranslateMatrix(P1_world);//创建一个新的图像引用所选的“myimage.jpg”vdImage img2 = new vdImage(doc);img2.ImageDefinition = imagedef ;img2.PenColor = new vdColor(Color.White, 100);//使图像透明img2.Transformby(m2);//将图像变换到绘图中的正确位置doc.Model.Entities.AddItem(img2); //将图像添加到模型绘图实体doc.Redraw(true);//强制重绘绘图

=======================================================

如果您对想要购买正版授权VectorDraw Developer Framework(VDF),可以联系在线客服>>咨询相关问题。

标签:

来源:慧都网

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年5月7日
下一篇 2021年5月7日

相关推荐

发表回复

登录后才能评论