且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们如何在不失去质量的情况下在C ++中调整图像大小?

更新时间:2023-09-16 23:18:34

[无耻的自我推销]

看看我的文章:普通C重采样DLL [ ^ ]。

[/ shameless sel-promotion]


您必须了解图像的呈现方式才能回答问题。



选择时一个用于显示的图像,它具有内在的最大分辨率,由图像的尺寸(像素)定义。



就图像质量而言,你能做的***,将显示图像的全尺寸。这很难实现,例如,12 MP图像需要3000x4000像素的屏幕。



为了使图像适合屏幕,你将会必须只显示一些像素。例如,您可以通过仅显示每隔一个像素(即,每个方向的一半数据,即数据的3 MP)将该图片压缩到1500x2000像素屏幕上。当然,这意味着丢失了一些细节。



实际上,你可能只会显示更像是十分之一的像素每个方向(300x400)(即图像数据的第100个)。它的细节会更少。



现在,如果调整大小是图像的非整数除数,你会得到一些内部算法的如何显示的想法数据(如果你很幸运)或一些非均匀分散的选择,一些数据不太正确,或一些缺失的行/列。



所以,你的问题的答案是:一个更大的再现应该,至少,保留(或甚至增强)细节(只要你不扩展超出真实图像的尺寸)。较小的演绎将失去细节。显示数据。 。 。或者没有。


您正在寻找的是由Penelope Garcia(犯罪心理)和Abby Sciuto(NCIS)(合作作者)制作的特殊图书馆,供他们独家使用。>


实际上,它不存在。否则,使用智能手机拍摄夜空的简单照片将会击败望远镜。

提高分辨率是上述同一个库的功能。 :)

How we can resize image in c++ without loosing its quality ? We can use GFL library also. I tried using StretchBlt.

What I have tried:

I tried using StretchBlt but quality of an image is losing, because of that I am not getting proper pixel value i want proper pixel value. Using GFL library I am getting that but speed is too slow. Can anyone help ?

[shameless self-promotion]
Have a look at my article: Plain C Resampling DLL[^].
[/shameless sel-promotion]


You must understand how an image is rendered to be able to answer the question.

When you select an image for display it has it's on intrinsic maximum resolution which is defined by the image's dimension (pixels).

The very best you can do, in terms of image quality, would be to display the image at it's full size. This is rarely possible as, for example, a 12 MP image would require a screen with 3000x4000 pixels.

To fit the picture on the screen, you're going to have to show only some of the pixels. For example, you could squeeze that picture onto a 1500x2000 pixel screen by only displaying every other pixel (i.e., half the data in each direction, which is 3 MP of the data). This means, of course, that some detail is lost.

In practical terms, you'll likely only be displaying something more like on 1 in 10 of the pixels in each direction (300x400) (i.e., 100th of the image's data). It will have even less detail.

Now, should the resizing be a non-integral divisor of the image, you'll get some internal algorithm's idea of how to display the data (if you're lucky) or some non-evenly-dispersed selection, some of the data just not quite right, or some missing rows/columns.

So, the answer to your question is: a larger rendition should, at least, preserve (or even enhance) the detail (so long you don't expand beyond the real image's dimensions). A smaller rendition will lose detail. The data is either displayed . . . or not.


What you are looking for is a special library made by Penelope Garcia (Criminal Minds) and Abby Sciuto (NCIS) (co-writers) for their exclusive usage .

In reality, it does not exist. Otherwise, a simple picture of the night sky with your smartphone would beat telescopes.
Improving resolution is a functionality od the same library above. :)