.NET中无法使用C#创建可缩放的png图像 [英] Unable to create a scalable png image using C# in .NET

查看:169
本文介绍了.NET中无法使用C#创建可缩放的png图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于字符串创建图像.图像必须是栅格图像(否则,如果我需要缩小图像,它将失去分辨率).我正在使用以下代码:

I am trying to create an image based on a string. The image needs to be raster (otherwise it will lose resolution if I need to zoom out). I am using the following code:

Bitmap bitmapimage = new Bitmap(200, 100);
Graphics bitmapGraphics = Graphics.FromImage(bitmapimage );   
bitmapGraphics .DrawString("test", new Font("Arial",50), Brushes.Black, new Point(0, 0));              
bitmapimage .Save("Image.png", System.Drawing.Imaging.ImageFormat.png);
textPictureBox.Image = bitmapimage ;

我得到的是这样的图像(缩放后):

What I get is an image like this (after zooming):

这是为什么?

推荐答案

我认为您误解了光栅"的含义.栅格图像是网格,每个网格位置有一个像素.当您放大光栅图像到足够远时,即使使用诸如抗锯齿之类的技术,网格也将变得清晰可见.

I think you misunderstand what "raster" means. Raster images are grids, with one pixel at each grid location. When you zoom on a raster image far enough the grid becomes clearly visible, even with techniques like anti-aliasing.

矢量图形基于算法.他们存储有关如何在给定画布上重现图像的说明.缩放矢量图像时,该图像将保持清晰,因为它仍然遵循指令,而不是简单地缩放先前的渲染.

Vector graphics, on the other hand, are algorithm based. They store instructions on how to reproduce an image on a given canvas. When you zoom a vector image, the image will stay sharp because it's still following the instruction, rather than simply scaling the previous rendering.

所有主要图像类型(bmp,gif,png,jpeg)都是栅格类型,并且不支持矢量图形. png图像是您的示例 光栅化的...实际上,不可能创建 not 光栅化的png图像.矢量图像的一个例子是某些字体类型或Photoshop(psd)文件(实际上是…的一种,Photoshop文件的栅格最终比矢量要更栅格化.)

All of the major image types (bmp, gif, png, jpeg) are raster types, and do not support vector graphics. The png image is your example is rastered... in fact, it's impossible to create a png image this is not rastered. An example of a vector image is certain font types or Photoshop (psd) files (sort of... in practice, Photoshop files tend to be more raster than vector in the end).

在这种情况下,最简单的解决方案可能是首先将图像绘制得非常大...足够大,您将不需要放大,并使用足够大的字体来填充空间.您还需要确保使用的是完全矢量绘制的字体.

In this case, probably the easiest solution is to draw the image very large in the first place... large enough that you won't need to zoom in, and use a large enough font to fill the space. You also need to make sure that you are using a font that is fully vector-drawn.

这篇关于.NET中无法使用C#创建可缩放的png图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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