I am trying to make an image enlarger that takes 500x500 pixel images and outputs a 1000x1000 pixel image that is exactly the same and with no distortion. I want it to work like this: for each pixel in the original image it should add 4 pixels of the same colour of that pixel into the new image and repeat for each pixel. So one pixel in the original becomes 4 pixels in the new one (4 pixels in a square). I have tried to make this but I cannot get it to work properly. I have written this so far but it just outputs the same size image on a 1000x1000 pixel image in the corner:
Bitmap oldImg = new Bitmap(Image.FromFile(@"C:\ServerSystem\Testing\20140127T154500.png"));
Bitmap newImg = new Bitmap(1000, 1000);
System.Drawing.Imaging.BitmapData data = oldImg.LockBits(new Rectangle(0, 0, 500, 500), System.Drawing.Imaging.ImageLockMode.ReadOnly, oldImg.PixelFormat);
oldImg.UnlockBits(data); byte[] rgba = new byte[data.Stride * 500];
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, rgba, 0, data.Stride * 500);
using (Graphics g = Graphics.FromImage(newImg))
{
for (int x = 0; x < 500; x++)
{
for (int y = 0; y < 500; y++)
{
newImg.SetPixel(x, y, Color.FromArgb(oldImg.GetPixel(x, y).ToArgb()));
newImg.SetPixel(x + 1, y, Color.FromArgb(oldImg.GetPixel(x, y).ToArgb()));
newImg.SetPixel(x, y + 1, Color.FromArgb(oldImg.GetPixel(x, y).ToArgb()));
newImg.SetPixel(x + 1, y + 1, Color.FromArgb(oldImg.GetPixel(x, y).ToArgb()));
}
}
newImg.Save(@"C:\ServerSystem\Testing\20140127T154500HIRES.png");
}
How can I make it work properly and get it to create 4 pixels out of 1? Thank you