Hello. In delphi written code:
result = (Image1.Canvas.Pixels[i, j] and $000000ff);
what it is mean? And if possible, please, say how can i do same operation in C#?
Edited: I don't know where problem: I use same algorithm, but result is not equivalent or same .i think i don't understand delphi code true!
Delphi code:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:byte;
noise_mass: array [0..255,0..255] of byte;
BN,BST:real;
mu:real;
begin
mu:=0.75;
Randomize;
for i:=0 to 255 do
begin
for j:=0 to 255 do
begin
noise_mass[i,j]:=Random(255);
BN:=BN+sqr(noise_mass[i,j]);
BST:=BST+sqr(image1.Canvas.Pixels[i,j] and $000000ff);
end;
end;
for i:=0 to 255 do
begin
for j:=0 to 255 do
begin
image1.Canvas.Pixels[i,j]:=image1.Canvas.Pixels[i,j]+round(mu*noise_mass[i,j]*BST/BN);
end;
end;
end;
C# code:
private Bitmap MakeNoise(Bitmap original)
{
double mu = 0.5;
Bitmap newBitmap = new Bitmap(256, 256);
double BN = 0, BST = 0;
byte[,] noise_mass = new byte[256, 256];
for (int i = 0; i <= 255; i++)
{
for (int j = 0; j <= 255; j++)
{
noise_mass[i, j] = (byte)(new System.Random(255)).Next();
BN = BN + Math.Pow(noise_mass[i, j], 2);
BST = BST + Math.Pow(original.GetPixel(i, j).R, 2);
}
}
for (int i = 0; i <= 255; i++)
{
for (int j = 0; j <= 255; j++)
{
int r = original.GetPixel(i, j).ToArgb() + (int)Math.Round(mu * noise_mass[i, j] * BST / BN);
Color c = Color.FromArgb(r);
newBitmap.SetPixel(i, j, c);
}
}
return newBitmap;
}