I am using a custom class to write an image onto another image of bigger size.
I am using a custom class to write an image onto another image of bigger size.doc - Google Drive[
^]
public class BitmapLockerTest
{
private static string path = @"locker.png";
public static void Run()
{
Bitmap image = Grayscale.ToGrayscale(Bitmap.FromFile(path) as Bitmap);
Bitmap canvas = Grayscale.CreateGrayscaleImage(1024, 256);
BitmapLocker imageLocker = new BitmapLocker(image);
BitmapLocker canvasLocker = new BitmapLocker(canvas);
imageLocker.Lock();
canvasLocker.Lock();
int startX = (Math.Abs(canvas.Width - image.Width) / 2);
int startY = (Math.Abs(canvas.Height - image.Height) / 2);
for (int y = startY; y < (startY + image.Height); y++)
{
for (int x = startX; x < (startX + image.Width); x++)
{
int xxx = x - startX;
int yyy = y - startY;
canvasLocker.SetPixel(x, y, imageLocker.GetPixel(xxx, yyy));
}
}
canvasLocker.Unlock();
imageLocker.Unlock();
new PictureBoxForm(canvas, image).ShowDialog();
}
}
Here is the full source code in DotNetFiddle.
Home | .NET Fiddle[
^]
But, it is generating a distorted image:
http://i.stack.imgur.com/rm3Nw.png[
^]
enter image description here
Probably, there has been some problems going on with reading and writing addresses.
But, I am unable to find the issue here.
P.S.2 :
Here is the input image[
^]
What I have tried:
public class BitmapLockerTest
{
private static string path = @"locker.png";
public static void Run()
{
Bitmap image = Grayscale.ToGrayscale(Bitmap.FromFile(path) as Bitmap);
Bitmap canvas = Grayscale.CreateGrayscaleImage(1024, 256);
BitmapLocker imageLocker = new BitmapLocker(image);
BitmapLocker canvasLocker = new BitmapLocker(canvas);
imageLocker.Lock();
canvasLocker.Lock();
int startX = (Math.Abs(canvas.Width - image.Width) / 2);
int startY = (Math.Abs(canvas.Height - image.Height) / 2);
for (int y = startY; y < (startY + image.Height); y++)
{
for (int x = startX; x < (startX + image.Width); x++)
{
int xxx = x - startX;
int yyy = y - startY;
canvasLocker.SetPixel(x, y, imageLocker.GetPixel(xxx, yyy));
}
}
canvasLocker.Unlock();
imageLocker.Unlock();
new PictureBoxForm(canvas, image).ShowDialog();
}
}