Bitmap Zoom Problem
Hi Friends,
I have written code for zooming bitmap and mouse drawing. The code is given below. Everything is working fine. But I find there is a strange behaviour like, when I feed the bitmap size 20 x 20 pixels, the zoomed bitmap shows only 19.5 x 19.5. Where is the half pixel is gone, else why the half pixel is not shown like other pixels. The first x pixel and first y pixel turned to be with this problem. I want to display all the pixels with equal size. Please help me. Also advise me how to avoid flickering when the image is drawn on the panel.
Code:
sing
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;using
System.Drawing.Drawing2D;using
System.Drawing.Design;namespace
WindowsApplication1{
publicpartialclassForm1 :Form{
Bitmap bmp;Graphics gp;Point prePoint, curPoint;Pen pen;public Form1(){
InitializeComponent();
bmp =
newBitmap(10, 10);gp =
Graphics.FromImage(bmp);pen =
newPen(Color.Red); this.DoubleBuffered =true;}
privatevoid panel1_MouseDown(object sender,MouseEventArgs e){
if (e.Button ==MouseButtons.Left)prePoint =
newPoint((1 + e.X / 10), (1 + e.Y / 10));}
privatevoid panel1_MouseMove(object sender,MouseEventArgs e){
if (e.Button ==MouseButtons.Left)curPoint =
newPoint((1 + e.X / 10), (1 + e.Y / 10));draw(e);
prePoint = curPoint;
this.panel1.Invalidate();}
privatevoid draw(MouseEventArgs e){
gp.DrawLine(pen, curPoint, prePoint);
}
privatevoid panel1_Paint(object sender,PaintEventArgs e){
Graphics gpp = e.Graphics;gpp.InterpolationMode =
InterpolationMode.NearestNeighbor;gpp.ScaleTransform(10.0f, 10.0f);
gpp.DrawImage(bmp, 0, 0);
}
}
}

