使用graphics.drawImage时的采样(差值)问题

orion_04 2004-10-17 09:03:06
在使用drawImage时,如果destRectangle和srcRectangle的大小不一样,操作时一定会有采样的问题.
但是我观察默认情况的采样,发现边缘存在锯齿,不光滑,所以我觉得很有可能时点采样,请问如果我
想使用线性(linear)采样该如何设置?

我的目的是使我缩小之后的图看起来光滑些. 有别的方法也可以
...全文
208 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
orion_04 2004-10-19
  • 打赏
  • 举报
回复
已经知道了.
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

orion_04 2004-10-19
  • 打赏
  • 举报
回复
我看过一个软件,他的第一版是采用普通的采样方式画出来的,第二版就是线性差值了.他也是用GDIPlus写的, 从他更新的速度上来看,应该使用了现成的方法. 我猜.
hivak47 2004-10-18
  • 打赏
  • 举报
回复
学习,帮你顶!!!!!!!!!!!!!!!
wangxt 2004-10-18
  • 打赏
  • 举报
回复
帮你顶
The123 2004-10-18
  • 打赏
  • 举报
回复
那只有自己动手了。看看下面这个对你又没有帮助。

http://www.bobpowell.net/lockingbits.htm

orion_04 2004-10-18
  • 打赏
  • 举报
回复
最常见的例子是WindowsXP的资源管理器的"显示缩略图", 如果使用
Bitmap bmp = new Bitmap(@"c:\A.jpg");
Bitmap bmpSave = new Bitmap(120, 90);
Graphics graphics = Graphics.FromImage(bmpSave);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphics.DrawImage(bmp, new Rectangle(0, 0, 120, 90), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel);
bmpSave.Save(@"c:\B.jpg", ImageFormat.Jpeg);
虽然大小和缩略图差不多,但是效果却差很多,使用上面的方法得到的图因为使用点采样,所以非常粗糙, 但是由于winXP采用的是线性差值, 所以看起来很光滑, 虽然有些模糊.
orion_04 2004-10-18
  • 打赏
  • 举报
回复
MSDN上面SmoothingMode的解释是:
Specifies whether smoothing (antialiasing) is applied to lines and curves and the edges of filled areas

我试过了,不是我要的效果. 我所要的线性差值的效果是在图像缩小的时候新图像上面的一个点是在源图像上面相关点的线性平均结果. 看起来就是稍微有些模糊, 但是很光滑, 不会有一个眼睛缩小之后变得不可见这样的感觉.
flybird079 2004-10-18
  • 打赏
  • 举报
回复
graphics.SmoothingMode = SmoothingMode.AntiAlias;
使用反锯齿
orion_04 2004-10-18
  • 打赏
  • 举报
回复
试了.但是好像没有效果.看帮助感觉不像是干这个的.
The123 2004-10-18
  • 打赏
  • 举报
回复
GDI+里有个"SmoothingMode"试了吗?
orion_04 2004-10-18
  • 打赏
  • 举报
回复
楼上的兄弟,我使用的就是drawImage函数,你这么做没有进行图片的stretchdraw啊.不是我想要的. 我现在要做的是将我的图光滑的缩小. 最好使用线性差值,而不是点采样.
Uncommon 2004-10-17
  • 打赏
  • 举报
回复
void MySampleDlg::OnPaint()
{
...
CPaintDC dc(this);
Gdiplus::Graphics do_draw(dc.m_hDC);

Gdiplus::Status ret_val = do_draw.GetLastStatus()
if (ret_val != Gdiplus::Ok)
{
OutputError(ret_val);
return;
}

Gdiplus::Bitmap bmp_obj(L"C:\\temp\\test_gdi_plus.bmp");
ret_val = do_draw.DrawImage(&bmp_obj, 0, 0, bmp_obj.GetWidth(), bmp_obj.GetHeight());
if (ret_val != Gdiplus::Ok)
{
OutputError(ret_val);
return;
}
}
张海霖 2004-10-17
  • 打赏
  • 举报
回复
不清楚,学习一下

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧