PDA

View Full Version : تبدیل یک کد دلفی به سی شارپ



programer1389
یک شنبه 23 شهریور 1393, 03:09 صبح
procedure ChangeTextColor(imgSource: TImage; x1, y1, x2, y2: Integer;
SelectColor: TColor; LineSpace: Integer);
var
i, j: Integer;
begin
j := y1;
if (j < (y2 - (LineSpace * 2 - 1))) then
begin
while j < y2 - LineSpace do
begin
for i := 0 to x1 do
if imgSource.Picture.Bitmap.Canvas.Pixels[i, j] <> clWhite then
imgSource.Picture.Bitmap.Canvas.Pixels[i, j] := SelectColor;
if y1 + LineSpace < j then
x1 := imgSource.Picture.Bitmap.Width -1;
inc(j);
end;
for j := y2 - LineSpace to y2 do
for i := x2 to imgSource.Picture.Bitmap.Width -1 do
if imgSource.Picture.Bitmap.Canvas.Pixels[i, j] <> clWhite then
imgSource.Picture.Bitmap.Canvas.Pixels[i, j] := SelectColor;
end
else
begin
i := y2 - y1;
i := i - LineSpace;
y2 := y2 - i;
for i := y1 to y2 do
for j := x2 to x1 do
if imgSource.Picture.Bitmap.Canvas.Pixels[j, i] <> clWhite then
imgSource.Picture.Bitmap.Canvas.Pixels[j, i] := SelectColor;
end;
end;


من برخی از کد رو متوجه نمیشم کسی میتونه کمک کنه؟

ابوالفضل عباسی
دوشنبه 24 شهریور 1393, 10:44 صبح
این هم همون کد به زبون c#:
فقط چون زبون دلفی نوشته بودی در c# بعضی از فرمان ها وجود نداره که در '//' نوشته ام.


// C#‎‎ does not allow bit fields:
private TImage x1, y1, x2, y2: int;
// The implementation of the following method could not be found:
// procedure ChangeTextColor(imgSource; TColor LineSpace: @int);
// Access declarations are not available in C#‎‎:
// SelectColor;
{
private int i;
private int j;


// The following statement was not recognized, possibly due to an unrecognized macro:
j = y1;
// The following method format was not recognized, possibly due to an unrecognized macro:
if ((j < (y2 - (LineSpace * 2 - 1))))
{
while (j < y2 - LineSpace)
{
for (i = 0; i <= x1; i++)
if (imgSource.Picture.Bitmap.Canvas.Pixels[i, j] != clWhite)
imgSource.Picture.Bitmap.Canvas.Pixels[i, j] = SelectColor;
if (y1 + LineSpace < j)
x1 = imgSource.Picture.Bitmap.Width - 1;
inc(j);
}
for (j = y2 - LineSpace; j <= y2; j++)
for (i = x2; i <= imgSource.Picture.Bitmap.Width - 1; i++)
if (imgSource.Picture.Bitmap.Canvas.Pixels[i, j] != clWhite)
imgSource.Picture.Bitmap.Canvas.Pixels[i, j] = SelectColor;
end else
{
i = y2 - y1;
i = i - LineSpace;
y2 = y2 - i;
for (i = y1; i <= y2; i++)
for (j = x2; j <= x1; j++)
if (imgSource.Picture.Bitmap.Canvas.Pixels[j, i] != clWhite)
imgSource.Picture.Bitmap.Canvas.Pixels[j, i] = SelectColor;
}
}