rasteredly放大/缩小GraphicsPath? [英] Zoom in/out a GraphicsPath rasteredly ?

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

问题描述

我可以在C#中快速放大/缩小GraphicsPath吗?我尝试使用Matrix.Scale()方法来模拟放大/缩小GraphicsPath,但似乎图形路径被放大/缩小,我希望它被光栅放大/缩小(就像你在MS中绘制一个椭圆形一样)油漆和放大/缩小椭圆形,缩放的形状是光滑的。)



你能告诉我任何实现这个目标的方法,我需要一些有效的表现(没有闪烁)。我的整体想法是在表格上绘制一些形状并尝试放大/缩小这些形状,就像在MS Paint中一样。



我的帮助将受到高度赞赏!

谢谢!



UPDATE !!!



这是链接您需要查看的图像:



#1 1xZoom



#2 4xZoom使用Matrix.Scale()方法,这是我首先尝试的方法



#3 4xZoom - 这是我想要的



#4 4xZoom - 这就是我在使用这个方法时所拥有的od建议你,它是一个真正的光栅形状



感谢您抽出时间深入挖掘我的问题!!!

Can I zoom in/out a GraphicsPath rasteredly in C#? I tried using Matrix.Scale() method to simulate zooming in/out a GraphicsPath, but it seems that the GraphicsPath is vectoredly zoomed in/out, I want it to be rasteredly zoomed in/out (like when you draw an oval in MS Paint and zoom in/out that oval, the zoomed shape is rastered).

Could you please show me any way to achieve this thing, I need something effective in performance (no flickering). The overall idea of mine is drawing some shapes on a form and try zooming in/out those shapes like as you do in MS Paint.

Your help would be highly appreciated!
Thanks!

UPDATE!!!

Here are links to images that you required to see:

#1 1xZoom

#2 4xZoom using Matrix.Scale() method, this is what I tried first

#3 4xZoom - This is what I want

#4 4xZoom - This is what I have when using the method suggested by you, it is a real rastered shape

Thank you for your time to dig into my problem!!!

推荐答案

您可以将路径绘制到位图上并放大。但即使Graphics.SmoothingMode设置为None,像素也会被插值。

因此,如果你真的想要看像素,你将不得不重复FillRectangle。上述位图的每个像素都有一个正方形。



哦,还有......为什么?





You could draw the path onto a bitmap and zoom into that. But the pixels will get interpolated, even with Graphics.SmoothingMode set to None.
So if you really want to see pixels, you will have to repeatedly FillRectangle. One square for each pixel of the mentioned bitmap.

Oh, and ... Why?


Bitmap ZoomPixelish(Image original, int scaleFactor)
{
    bitmap zoomedImage = new Bitmap(original.Width * scaleFactor, original.Height * scaleFactor);
    Graphics g = Graphics.FromImage(zoomedImage);
    for(int y = 0; y < original.Height; y++)
    {
        for(int x = 0; x < original.Widht; x++)
        {
            g.FillRectangle(
                new SolidBrush(original.GetPixel(x,y)),
                x * scaleFactor,
                y * scaleFactor,
                scaleFactor,
                scaleFactor
            );
        }
    }
}



未经测试。但你应该得到这个意图。错误修正和优化取决于你(黑白图像不需要每个像素的新SolidBrush; LockBits而不是GetPixel)

[/ Edit]


That''s not tested. But you should get the intention. Bugfixing and optimization are up to you (a black-and-white image doesn''t need a new SolidBrush for every pixel; LockBits instead of GetPixel)
[/Edit]


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

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