أحتاج تحجيم الصورة إلى مستعارة في C#
سؤال
قد يكون هذا السؤال غريبا ، ولكن عندما الحجم صورتي في C# أريد لها أن تكون منقطة وليس مكافحة مستعارة.فقط مثل في MSpaint عندما الحجم.
أتمنى الصور anti-alias بشكل افتراضي في C# أو آخر لم يتغير شيء لم أكن أريد أن.
لقد حاولت اللعب حولها مع Graphics.InterpolationMode
ولكن لم الحظ هناك.أنا باستخدام كائن صورة نقطية لعقد صورة و يجري بناؤها مثل ذلك:
// A custom control holds the image
this.m_ZoomPanPicBox.Image = new Bitmap(szImagePath);
موجزا synapsis من التحكم المخصصة:
class ZoomPanPicBox : ScrollableControl
{
Image m_image;
float m_zoom = 1.0f;
InterpolationMode m_interpolationMode;
...
////////////////////////////////////////////////////////
public ZoomPanPicBox()
{
//Double buffer the control
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
this.AutoScroll=true;
}
////////////////////////////////////////////////////////
protected override void OnPaint(PaintEventArgs e)
{
//if no image, don't bother
if(m_image==null)
{
base.OnPaintBackground(e);
return;
}
//Set up a zoom matrix
Matrix mx = new Matrix(m_zoom,0,0,m_zoom,0,0);
//now translate the matrix into position for the scrollbars
mx.Translate(this.AutoScrollPosition.X / m_zoom, this.AutoScrollPosition.Y / m_zoom);
//use the transform
e.Graphics.Transform = mx;
//and the desired interpolation mode
e.Graphics.InterpolationMode = m_interpolationMode;
//Draw the image ignoring the images resolution settings.
e.Graphics.DrawImage(m_image,new Rectangle(0,0,this.m_image.Width,this.m_image.Height),0,0,m_image.Width, m_image.Height,GraphicsUnit.Pixel);
base.OnPaint(e);
}
أي أفكار ؟ شكرا
المحلول
في الواقع, كنت مع InterpolationMode ، يقول الأطباء.فقط تعيين إلى InterpolationMode.NearestNeighbor.في نموذج التعليمات البرمجية, لم m_interpolationMode.
نصائح أخرى
حسنا, هل يمكن أن تنفذ على نطاق نفسك و لا بسيطة الخطية (I. E.لا تفعل أي جار المتوسط مثل التكعيبي)...هذه تبدو لطيفة و ممتلئ الجسم.
لا تنتمي إلى StackOverflow