简体   繁体   English

将(8 * 7 px)位图图像调整为800 x 700

[英]Resize (8 * 7 px) Bitmapimage to 800 x 700

I created about 100 png files that are all 8*7 pixels in size, they contain tiny faces. 我创建了大约100 png文件,这些文件的大小均为8*7 pixels ,它们包含微小的面孔。

I wanted to display one of the faces in a WPF Image , to do so, I created a Bitmapimage (using the Stretch.Fill option) and put the png into it's urisource, then I used the bitmapimage as the images source. 我想在WPF Image显示其中一张脸,为此,我创建了一个Bitmapimage(使用Stretch.Fill选项),并将png放入其urisource中,然后将bitmapimage用作图像源。

As you can imagine, it looks kinda weird, all I wanted to do was to get a bigger picture, not to change any pixels (like when you use windows image viewer and zoom into it, there's no quality loss and the pixels don't change, meaning that you don't loose the shapes and colors of the image) 可以想象,看起来有点奇怪,我要做的就是获取更大的图片,而不更改任何像素(例如,当您使用Windows图像查看器并放大它时,没有质量损失,像素也没有变化,这意味着您不会松开图像的形状和颜色)

I'm sure there's a way to just "zoom" into my 8*7px picture, or to copy those pixels and draw them again, but bigger. 我敢肯定有一种方法可以"zoom"我的8*7px图片,或者复制这些像素并再次绘制它们,但是更大。

I'm really sorry for my bad english, I still hope you understand me and are able to help. 非常抱歉我的英语不好,我仍然希望您能理解我并能提供帮助。

Thank you very much in advance, there's really nothing more to say. 预先非常感谢您,实际上没有什么可说的了。

I imagine the resulting image looks rather blurry. 我想象得到的图像看起来很模糊。 The reason isn't "loss" of quality - instead, it's extrapolating the detail that simply isn't in the original image. 原因不是质量的“损失”-而是推断出原始图像中根本没有的细节。 And for photos and similar images, it's usually a better idea to use some smooth interpolation, so that's what WPF does. 对于照片和类似图像,使用一些平滑插值通常是一个更好的主意,因此WPF就是这样做的。

I'm not sure if there's a better way in WPF (it might), but you can manually create a new bitmap without the smooth interpolation like this: 我不确定WPF中是否有更好的方法(可能),但是您可以手动创建新的位图,而无需进行平滑插值,如下所示:

var src = new Bitmap("D:\\Untitled.png");
var dst = new Bitmap(800, 700);

using (var gr = Graphics.FromImage(dst))
{
  gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
  gr.DrawImage(src, new Rectangle(0, 0, 800, 700));
}

dst.Dump();

The dst variable will have the resized bitmap with "nearest neighbour" interpolation - the "pixelated" look. dst变量的大小调整后的位图将带有“最近邻居”插值-“像素化”外观。

EDIT: 编辑:

The WPF-native way would be to use RenderOptions.BitmapScalingMode="NearestNeighbor" . WPF本机方式是使用RenderOptions.BitmapScalingMode="NearestNeighbor" If you're creating the images dynamically, this corresponds to RenderOptions.SetBitmapScalingMode(bmp, BitmapScalingMode.NearestNeighbor) of course. 如果要动态创建图像,则它当然对应于RenderOptions.SetBitmapScalingMode(bmp, BitmapScalingMode.NearestNeighbor)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM