本文介绍了GDI +和大小调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我在使用GDI +调整位图大小时遇到​​一些奇怪的问题.

说我有一个JPEG图像10000x5000.我用它的原始尺寸显示它的当前零件:

Hi all.
I have some odd problem with resizing bitmaps using GDI+.

Say i have an jpeg image 10000x5000. I display it''s current part in original size with this:

graphics->DrawImage(bitmap, -x, -y, bitmap->GetWidth(), bitmap->GetHeight());



其中x,y是当前移动的坐标.

我正在调整图像的尺寸,如下所示:



where x,y are coordinates of current shifting.

I''m resizing image like this:

Bitmap* newBitmap = new Bitmap((INT)(bitmap->GetWidth()*Scale), (INT)(bitmap->GetHeight()*Scale));
Graphics* graphics = new Graphics(newBitmap);
graphics->ScaleTransform(Scale, Scale);
graphics->DrawImage(bitmap, (INT)0, (INT)0, (INT)(bitmap->GetWidth()), (INT)(bitmap->GetHeight()));



现在的问题是:
当我直接从文件加载图像时,显示非常快速,美观且没有延迟.但是,当我显示调整大小的图像时,即使它变小了,绘图操作也要花很多时间.

我尝试设置不同的InterpolationMode,SmoothingMode,PixelOffsetMode,但没有效果.我试图解决这个问题很长时间.尝试了不同的方法,但是它们都没有效果.也许我缺少明显的东西?也许文件位图"中的某些信息丢失了?像素格式始终相同.好吧,现在我没有别的主意了,所以我希望有人可以帮助我解决我的问题.

忘了说我正在使用普通的winapi,因此.NET解决方案无法帮我.



And now the problem:
When I''m loading image direct from file, displaying works very fast, nice and without delays. But when i display resized image, even if it became smaller, drawing operation takes a lot more time then it was.

I have tried setting different InterpolationMode, SmoothingMode, PixelOffsetMode but it had no effect. I''m trying to manage with this problem for a long time. Tried different ways, but all they had no effect. Maybe I''m missing something obvious? Maybe some information from "file bitmap" gets lost? Pixel format is always the same. Well, now I don''t have any other ideas, so I hope someone can help me with my issue.

Forgot to say that I''m using plain winapi, so .NET solution can''t help me.

推荐答案

float width = bitmap->GetWidth()* Scale;
float height = bitmap->GetHeight()* Scale;
 
Graphics* graphics = new Graphics(bitmap);
graphics->TranslateTransform(width , height); 
graphics->ScaleTransform(Scale, Scale);
graphics->DrawImage(bitmap, (INT)0, (INT)0, (INT)width, (INT)height);




这篇关于GDI +和大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:16