在像素之间插入空间
我需要能够使用 GDI 在屏幕上绘制特定分辨率(~40 DPI)的位图,并且还能够复制每个像素之间的间距。 该空间只是像素大小的一小部分,但肉眼是可以注意到的。
是否有办法设置 Graphics 类或位图以使其在绘制的像素之间插入“空白”? 在我自己编写复杂的代码来完成之前,我想确保没有遗漏任何设置。
I need to be able to draw a bitmap that is at a specific resolution (~40 DPI), on screen using GDI, and also be able to replicate spacing between each pixel. The space is a fraction of the pixel size, but it is noticeable to the eye.
Is there anyway to setup the Graphics class or a Bitmap to have it insert "white space" between drawn pixels? Before I go after writing the complicated code to do it myself, I'd like to make sure there isn't some setting I'm missing somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想要将图像从 40 dpi 拉伸到显示器的 ~110 dpi,但不是扩展像素,而是每英寸仅绘制 40 个像素,其余部分为白色。
我不知道 GDI 中有任何东西可以做到这一点。 另外,除非您进行整数缩放,否则它看起来会非常糟糕 - 即原始位图中的每个像素恰好有一个或两个白色像素,这将严重限制您对最终尺寸的选择。 您也许可以通过使用子像素渲染(例如 ClearType)对此进行一些调整,但这将是您必须编写的更专业的代码(并且特定于显示器!)。 就目前而言,您可能必须逐个像素地构造一个新的位图。
您可以通过创建一个大小为源位图 3x3 倍的新位图,将其绘制为白色,并且(伪代码)
您可能需要添加一些单像素调整以获得边缘周围漂亮的白色边框,从而获得相当接近的效果。
这仍然会留下 5/9 的像素为白色,这意味着您将得到一个非常褪色的图像。
您是否想模仿旧显示器或其他东西?
It sounds like you want to stretch an image from 40 dpi up to the ~110 dpi of a monitor, but rather than expanding the pixels, still only draw 40 pixels per inch and have the rest be white.
I don't know of anything in GDI that does this. Also, it'll look really bad unless you do integer scaling - i.e. exactly one or two white pixels for every pixel in the original bitmap, which will severely limit your options for the final size. You might be able to tweak that a bit by using subpixel rendering (e.g. ClearType), but that'll be even more specialized code (and monitor-specific!) you'll have to write. As it stands now, you're probably going to have to construct a new bitmap pixel-by-pixel.
You can get reasonably close by creating a new bitmap that is 3x3 times the size of your source bitmap, painting it white, and (pseudocode)
You might want to add some single-pixel adjustments to get a nice white border around the edge.
This still leaves 5/9 of your pixels white, meaning you'll have a very washed-out image.
Are you trying to emulate an old display or something?
.Net 中的位图没有任何像素之间空间的逻辑概念。 我想你必须自己写这个。 当您执行此操作时,请确保使用位图的 LockBits 方法访问数据 - SetPixel 和 GetPixel 的速度慢得令人难以置信。
更新:我今天很无聊,想给你写这篇文章。 如果没有人有好的答案,我会在午餐后完成。
A Bitmap in .Net doesn't have any logical conception of the space between pixels. I think you'll have to write this yourself. When you do this, make sure you access the data using the Bitmap's LockBits method - SetPixel and GetPixel are unbelievably slow.
Update: I'm so bored today I want to write this for you. If no one else has a good answer, I'll do it after lunch.