Graphics.DrawImage(Image,RectangleF) does not work as expected

Jul 19, 2011 at 12:07 PM

hello

 

 

hello

 i've created a BitMap 1 pixel wide & 256 pixel height
 when i try to draw this bitmap as 2 pixels wide using:

   public void DrawImage(Image image,RectangleF rect)
 
   the bitmap is not drawns ok that is there are white
   slim stripes in bitween each bitmap column.
   see the simple code below

        private void Form1_Paint(object sender,
                                 PaintEventArgs e)
        {
            Graphics gr = e.Graphics;
           
            Bitmap bitmap = new Bitmap(1, 256);
            for (int y = 0; y < 256; y++)
            {
                bitmap.SetPixel(0, y, Color.Red);
            }

            RectangleF rectf = new RectangleF();

            for (int x = 0; x < 500; x++)
            {
                float factor = 2;
                rectf.X = x*factor;
                rectf.Y = 0;
                rectf.Width = fact;
                rectf.Height = 500;
  // should draw bitmap as 2 pixels wide
  // but draws it with white slim stripes in between
  // each bitmap colomn
                gr.DrawImage(bitmap, rectf);
            }          
        }