C#에서 별명을 사용하려면 스케일링 된 이미지가 필요합니다.
문제
이것은 이상한 질문 일 수 있지만 C#에서 내 이미지를 확장 할 때는 픽셀 화되고 반 알리 아스가 아닌 것이 필요합니다. MSPAINT와 마찬가지로 확장 할 때 마찬가지로.
C#에서 기본적으로 이미지 anti-alias를 희망합니다. 그렇지 않으면 원하지 않는 것을 변경했습니다.
나는 함께 놀아 보았다 Graphics.InterpolationMode
그러나 거기서 운이 없습니다. 비트 맵 객체를 사용하여 이미지를 보유하고 있는데 그렇게 구성되고 있습니다.
// A custom control holds the image
this.m_ZoomPanPicBox.Image = new Bitmap(szImagePath);
그리고 사용자 정의 컨트롤의 간단한 시냅스 :
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.nearestneighbor로 설정하십시오. 코드 샘플에서는 m_interpolationMode를 설정하지 않습니다.
다른 팁
글쎄, 당신은 스케일을 직접 구현하고 간단한 선형 보간을 할 수 있습니다 (즉, Bicubic과 같은 이웃 평균화는하지 않습니다 ... 그것들은 멋지고 차단됩니다.
제휴하지 않습니다 StackOverflow