C# 的高效缩放

发布于 2024-07-29 23:40:58 字数 479 浏览 19 评论 0原文

要放大和缩小图像,有一种可能的方法来调整图片框的大小并以拉伸模式显示图像。 虽然我不能有效地使用它,因为一般超过 8 倍它会给出存储错误 [认为图片框的大小(32k,32k)它需要超过 1GB 内存!

是否有特殊方法,或者我应该使用 ImageClone 仅缩放图像的可见部分?

更新:

这是项目,首先尝试缩放项目[不可能,存储错误],然后删除form.cs中的41行:

pictureBox1.Image = youPicture;

删除此行后,程序将运行,请移动缩放的图像。

这是链接: http://rapidshare.com/files/265835370/zoomMatrix.rar .html

To zoom images in and out, there is a possible way to resize the pictureBox and showing image in strechmode. Although I can not use it efficiently becauce in general over 8x it gives storage error [think that a pictureBox has the Size(32k, 32k) it needs over 1GB memory !

Is there a special method, or should I zoom only the seen part of the image by using ImageClone ?

Update:

Here is the project at first try to zoom at the project [impossible, storage error] than delete the 41. line in form.cs :

pictureBox1.Image = youPicture;

After deleting this line, the program will work, please move the zoomed image.

Here is the link: http://rapidshare.com/files/265835370/zoomMatrix.rar.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如果没有 2024-08-05 23:40:58

通过使用矩阵对象和图形对象的变换属性:

using(Graphics g = this.CreateGraphics())
{
    using(Bitmap youPicture = new Bitmap(yourPictureFile))
    {
        g.DrawImage(youPicture, 0, 0, 300, 100); //set the desired size

        //Now you need to create a matrix object to apply transformation on your graphic
        Matrix mat = new Matrix();
        mat.Scale(1.5f, 1.5f, MatrixOrder.Append); //zoom to 150%
        g.Transform = mat;

        g.DrawImage(youPicture, new Rectangle(...), 0, 0, youPicture.Width,
            youPicture.Height, GraphicsUnit.Pixel) ;
    }
}

By using the matrix object and the transform property of your graphics object:

using(Graphics g = this.CreateGraphics())
{
    using(Bitmap youPicture = new Bitmap(yourPictureFile))
    {
        g.DrawImage(youPicture, 0, 0, 300, 100); //set the desired size

        //Now you need to create a matrix object to apply transformation on your graphic
        Matrix mat = new Matrix();
        mat.Scale(1.5f, 1.5f, MatrixOrder.Append); //zoom to 150%
        g.Transform = mat;

        g.DrawImage(youPicture, new Rectangle(...), 0, 0, youPicture.Width,
            youPicture.Height, GraphicsUnit.Pixel) ;
    }
}
橘虞初梦 2024-08-05 23:40:58

我个人只会缩放可见部分,因为其余部分无论如何都是隐藏的(因此没有用)

I personally would just zoom the visible part as the rest is hidden anyway (and thus no use)

花落人断肠 2024-08-05 23:40:58

请参阅之前问题的此答案。 您绝对不想通过使图像变大并仅显示其一部分来进行缩放 - 您将遇到已经遇到的内存问题。 另外,图片框的拉伸模式不使用高质量插值,因此结果看起来非常糟糕。

在我在这里链接的答案中,我包含了一个 C# 项目的链接,该项目向您展示了如何进行这种缩放。

更新:这里是可下载项目的直接链接

See this answer to an earlier question. You definitely don't want to zoom by making the image huge and showing only part of it - you'll run into the memory problem that you've already encountered. Also, the stretch mode of a picture box doesn't use high-quality interpolation, so the result will look pretty crappy.

In the answer I linked here, I included a link to a C# project that shows you how to do this kind of zooming.

Update: here is a direct link to the downloadable project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文