for(i=height-1;i>=height-count;i--)此句如何转为delphi程序? ( 积分: 200 )

  • 主题发起人 主题发起人 rzqcjwrz
  • 开始时间 开始时间
var i:integer;
begin
for i:=height-1 downto height-count do begin
你的处理程式...;
...............;
end;
end;

var i:integer;
begin
i:=height-1;
while i>=height-count do begin
你的处理程式...;
...............;
dec(i);
end;
end;
或者
.......
 
C++的For语句相当于Delphi的While循环
for(i=height-1;i>=height-count;i--)就等价

i:=Height-1;
While (i>=Height-Count) do
begin
//循环内容
Dec(I);
end;
 
我看,应该是红色部分有误吧,number ==>> number - 1
代码:
procedure TMyPicture.LevelProjection(Bitmap: TBitmap; Level: Boolean);
var
   X, Y, i, j: integer;
   P, Q: pByteArray;
   newbmp: TBitmap;
   number: integer;
begin
   newbmp := TBitmap.Create;
   // 动态创建TBitmap对象
   newbmp.Width := bitmap.Width;
   newbmp.Height := bitmap.Height;
   //原位图的高度和宽度赋给新的位图
   newbmp.Assign(bitmap);
   // 拷贝位图到newbmp
   if (Level) then //Level为真表示进行水平投影
   begin
      for X := 0 to bitmap.Width - 1 do
      begin
         P := newbmp.ScanLine[X];
         Q := bitmap.ScanLine[X];
         number := 0;
         // 设置每一列扫描的初值
         for Y := 0 to bitmap.Height - 1 do
         begin
            if ((Q[3 * Y + 2] = 255) and (Q[3 * Y + 1] = 255) and (Q[3
               * Y] = 255)) then
               number := number + 1;
            // 统计每一行的白色点的数目,记录为number
         end;
         for i := 0 to [:D][h1][u][b][red]number-1[/red][/b][/u][/h1] do
         begin
            P[3 * i] := 0;
            P[3 * i + 1] := 0;
            P[3 * i + 2] := 0;
         end;
         // 从上面开始,给一列number个像素点涂上黑色
         for j :=bitmap.Height - 1  downto bitmap.Height - number do
         begin
            P[3 * j] := 255;
            P[3 * j + 1] := 255;
            P[3 * j + 2] := 255;
         end;
         // 其他点涂白色
      end;
      bitmap.Assign(newbmp);
      newbmp.Free;
   end;
end;
 
procedure TMyPicture.LevelProjection(Bitmap: TBitmap; Level: Boolean);
var
X, Y, i, j: integer;
P, Q: pByteArray;
newbmp: TBitmap;
number: integer;
begin
newbmp := TBitmap.Create;
// 动态创建TBitmap对象
newbmp.Width := bitmap.Width;
newbmp.Height := bitmap.Height;
//原位图的高度和宽度赋给新的位图
newbmp.Assign(bitmap);
// 拷贝位图到newbmp
if (Level) then //Level为真表示进行水平投影
begin
for X := 0 to bitmap.Width - 1 do
begin
P := newbmp.ScanLine[X];
Q := bitmap.ScanLine[X];
number := 0;
// 设置每一列扫描的初值
for Y := 0 to bitmap.Height - 1 do
begin
if ((Q[3 * Y + 2] = 255) and (Q[3 * Y + 1] = 255) and (Q[3
* Y] = 255)) then
number := number + 1;
// 统计每一行的白色点的数目,记录为number
end;
for i := 0 to [blue]number[/blue] do
begin
P[3 * i] := 0;
P[3 * i + 1] := 0;
P[3 * i + 2] := 0;
end;
// 从上面开始,给一列number个像素点涂上黑色
for j :=bitmap.Height - 1 downto bitmap.Height - number do
begin
P[3 * j] := 255;
P[3 * j + 1] := 255;
P[3 * j + 2] := 255;
end;
// 其他点涂白色
end;
bitmap.Assign(newbmp);
newbmp.Free;
end;
end;
 
number 的颜色和格式不能变,真奇怪!
 
qhbo:
hell.
你说的方法我试了,还是报错:Scan Line index out of range.
 
for X := 0 to bitmap.Width - 1 do


改成

for X := 0 to bitmap.Height - 1 do

看看
 
下面的width和height类似变化,看看能不能满足你的要求

Provides indexed access to each line of pixels.

property ScanLine[Row: Integer]: Pointer;

Description

ScanLine is used only with DIBs (Device Independent Bitmaps) for image editing tools that do low-level pixel work.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部