读书人

Delphi翻译成C# 很简短 大家帮上忙

发布时间: 2012-09-07 10:38:15 作者: rapoo

Delphi翻译成C# 很简短 大家帮下忙

Delphi(Pascal) code
procedure TAPOS.Bitmap24Print(X, Y: Integer; Bmp: TBitmap);var   YLp:   Integer;   XLp:   Integer;   b:     Byte;   ABmp:  TBitmap;   P : PByteArray;   S:  String;   W:   Integer;   H:   Integer;begin     try        ABmp             := TBitmap.Create;        ABmp.Width       := Bmp.Width;        ABmp.Height      := Bmp.Height;        ABmp.Assign(Bmp);        ABmp.PixelFormat := pf1bit;        ABmp.Monochrome  := True;        Sendc(ESC);        Sends('I');        S := format('%4.4d', [X + FAdjustPoint]);        S := Copy(S, 1, 4);        Sends(S);//        S := format('%4.4d', [Y + FLine]);        S := Copy(S, 1, 4);        Sends(S);//        W := ABmp.Width div 8;        H := ABmp.Height;        S := format('%3.3d', [W]);        S := Copy(S, 1, 3);        Sends(S);//        S := format('%3.3d', [H]);        S := Copy(S, 1, 3);        Sends(S);//        for YLp := 0 to H - 1 do        begin             P := ABmp.ScanLine[YLp];             for XLp := 0 to W - 1 do             begin                  b := not P[XLp];                  Sendc(b);             end;        end;        //ABmp.SaveToFile('MINTEST.BMP');     finally        ABmp.Free;     end;end;

主要是:
for YLp := 0 to H - 1 do
begin
P := ABmp.ScanLine[YLp];
for XLp := 0 to W - 1 do
begin
b := not P[XLp];
Sendc(b);
end;
end;
这段搞不懂,还有P的定义。意思大概懂,就是ScanLine,在C#里是什么方法


[解决办法]
基本的数据类型你应该知道吧!TBitmap我只知道是一个用于图形的类,可能是抓图用的吧。P:PByteArray应该是一个Byte数据的指针,用于存二进制数组。
而你所说的这段
for YLp := 0 to H - 1 do
begin
P := ABmp.ScanLine[YLp];
for XLp := 0 to W - 1 do
begin
b := not P[XLp];
Sendc(b);
end;
end;
是用ABmp.ScanLine[YLp];逐行扫描存于ABmp里的图片,以二进制读取,然后再把读取出来的一行二进制以8个二进行数用sendc()方法发送出去(sendc应该是自己写的一个方法吧),即16进制。其中H是ABmp里图片的高度(即行数),W是ABmp里图片的行数的1/8(即把列数以8个为一组分成W个组)。
以上是我个人的理解,希望是正确的,对你有帮助!
[解决办法]
C#中没有这样直接的方法对图片进行整行的取象素值。
[解决办法]
试试这种方法
How to access all the pixels of a bitmap with C#



[解决办法]
FreeImage
freeimage里面提供了ScanLine方法

读书人网 >.NET

热点推荐