动态图像缩放 [英] dynamically image zoom

查看:86
本文介绍了动态图像缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态缩放图像。并在图像上绘制形状

how to dynamically zoom image. and draw shapes on image

推荐答案

请参阅我最近关于缩放的答案:在C#.net鼠标滚轮中缩放图像 [ ^ ]。



绘图图像上的形状非常相似。您可以从文件中加载源图像,其中某些内容可以是您的形状的背景,拍摄已经缩放的图像,如上面引用的答案中所述。此时,您已经可以使用 System.Graphics 的实例来绘制图像。如果不使用缩放,则前面的步骤说明了如何获取此类实例。这样,您可以使用原始或缩放的图像,并在其上面添加一些绘图。



对于ASP.NET,您还需要一个步骤。您可以在服务器端保存图像,并在ASP.NET页面上生成的< img> 元素中引用它。但更有可能的是,您需要动态生成图像,而无需保存文件。在这种情况下, img src 属性中使用的URI应指向使用类 System.Net.HttpResponse 和适当的内容类型会告诉浏览器它是某种类型的图像:

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx [ ^ ]。



上面引用的MSDN文章中显示的代码示例恰好是您所需要的,生成JPEG文件,但您可以生成PNG或其他任何内容。



-SA
Please see my recent answer about zooming: Zoom image in C# .net mouse wheel[^].

Drawing shapes on the image is very similar to that. You can have a source image loaded from file, with something which would be a background for your shapes, the take the image which is already zoomed as described in my answer referenced above. At this moment, you already have the instance of System.Graphics you can use for drawing on the image. If you don't use zoom, the previous steps explains how to obtain such instance. This way, you can have original or zoomed image with some drawing on top of it.

For ASP.NET, you will need one more step. You either save your image on the server side and reference it in the <img> element generated on your ASP.NET page. But more likely, you would need to generate images on the fly, without saving a file. In this case, the URI used in the img src attribute should point to ASPX generating the image by using the class System.Net.HttpResponse and appropriate content type which will tell the browser it's an image of certain type:
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx[^].

The code sample shown in the MSDN article referenced above happens to be exactly what you need, generating a JPEG file, but you can generate PNG or anything else.

—SA


http://tinyurl.com/lck2yoo [ ^ ]


这篇关于动态图像缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆