本文介绍了在没有“大方块"的情况下放大图像(游戏地图).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在一个游戏中工作,该游戏中有动态高度和宽度的地图(例如30x30).在一个屏幕上,我想向更大的用户显示地图(政治地图).假设我要以600x600显示.
我知道,我可能无法使用.NET的经典方式,因为当我调整.NET的大小时,它就变得模糊了.避免模​​糊的唯一方法是设置InterpolationMode.NearestNeighbor.但是使用时是平方".
我只是想知道一件事-是否有一种调整大小的方法,该方法可以从旧像素中近似新像素而不是模糊它?

例举

我使用的是System.Drawing,而不是WPF

Hi,
I work on a game where is a map of dynamic height and width (for example 30x30). On one screen I want to display the map to user bigger (political map). Let''s say I want to display it in 600x600.
I understand, I probably cannot use classic ways of .NET, because when I resize it, it is blurred. The only way to not have it blurred is to set InterpolationMode.NearestNeighbor. However is is "squared" when I use it.
I am just wondering about one thing -Is there a resize method, which can approximate the new pixels from the old one instead of blurring it?
Something like
exaxmple

I use System.Drawing, not WPF

推荐答案


  1. 使用与以前相同的代码示例,并查看如何使用LockBitsMarshal写入位图.主要区别是:您需要创建另一个位图进行渲染,将其放大N倍,并使用从原始位图读取的像素数组设置其中的所有像素

  1. Use the same code sample as before and see how to write to a bitmap using LockBits and Marshal. The main difference is: you need to create another bitmap for rendering, N time bigger and set all pixels in it using the pixel array read from the original bitmap



很难说哪种方法会更快.它也可能取决于您的缩放比例.请尝试一下.如果您分享您的结果,那就太好了.


无论如何,通过重新采样进行缩放是完全错误的方法.

您只需要使用矢量图形即可.有几种选择:使用您自己的数据层(向量基元的集合,无比例缩放,可伸缩)和针对每个比例动态渲染,基于图元文件进行渲染.我真的不想讨论这个问题,因为WPF胜过一切.它已经具有成熟的矢量图形,其中包含任何复杂性的对象,设计时或运行时,完全实现的缩放比例等等.几乎没有底层编程.完全没有渲染.我什至不愿意使用表单的想法.我希望它们已经过时了.
[END EDIT]

—SA



Hard to say which method will be faster; it may also depends on your scaling factor. Please experiment. Would be nice if you share your results.


Scaling via re-sampling is completely wrong approach anyway.

You need to use vector graphics and nothing else. There are several options: using your own data layer (collection of vector primitive, scale-free, scalable) and rendering on the fly for each scale, rendering based on metafile. I don''t really want to discuss this because WPF beats all. It already has fully-fledged vector graphics with objects of any complexity, design-time or run-time, fully implemented scaling and more. Almost no low-level programming. No rendering at all. I would not even play with the idea of using Forms. They are getting obsolete anyway, I hope.
[END EDIT]

—SA


这篇关于在没有“大方块"的情况下放大图像(游戏地图).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:53