为什么edit.text里有两个字符是运行不了 |
尚未結案
|
小丫123
初階會員 ![]() ![]() 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
Type D1Array=array of double; D2Array=array of array of double; imgwidth,imgheight,imagewidth,imageheight:integer; procedure TForm1.Button1Click(Sender: TObject); var i,j,k:integer; w,h,num:integer; s,Data:D2Array; max:double; rect:Trect; E:WideString; t:string; begin memo1.Clear ; setlength(s,imagewidth,imageHeight); setLength(data,10,imagewidth*imageHeight); E:= charedit.Text; num:=length(E ); for k:=0 to num-1 do begin Img.Canvas.Font.Color := clBlack; Img.Canvas.Font.Size := 42; if E <> '' then begin img.Canvas.TextOut(0, 0, E[k 1]) ; Aimg.picture.Bitmap.Assign(img.picture.Bitmap); end; if img <> nil then begin img.Width:= imgwidth; img.height:=imgheight; w:=img.Width mod imagewidth; img.Width:=img.Width imagewidth-w; w:=img.Width div imagewidth; h:=img.Height mod imageHeight; img.Height :=img.Height imageHeight -h; h:= img.Height div imageHeight; max:=0; for i:=1 to imagewidth-1 do for j:=1 to imageHeight-1 do begin rect.Left :=w*(i-1); rect.Top :=h*(j-1); rect.Right :=rect.Left w-1; rect.Bottom :=rect.Top h-1; s[i,j]:=statistic(rect,img); if s[i,j]>max then max:=s[i,j]; end; for j:=0 to imageHeight-1 do begin for i:=0 to imageWidth-1 do begin if s[i,j]/max >0.2 then Data[k,j*imagewidth i-k*imagewidth]:=0.9 else Data[k,j*imagewidth i-k*imagewidth]:=0.1; end; end; end; t:=''; for j:=0 to 19 do begin t:=' '; for i:=0 to 15 do begin if Data[k,j*16 i]>=0.8 then t:= t '#' ' ' ; if (Data[k,j*16 i]<=0.2) then t:= t '0' ' ' ; end; memo1.Lines.Add(t); end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin imgwidth:=42; imgheight:=60; imagewidth:=16; imageheight:=20; end; function TForm1.Statistic(const rect: Trect; img: Timage): integer; var x,y:integer; begin Result:=0; for x:=rect.Left to rect.Right do for y:=rect.Top to rect.Bottom do if img.Canvas.Pixels[x,y]<>16777215 then inc(result); end;在我这个程序中,当charedit.tex是一个字符是运行结果是对的,当输入两个字符时就报错。 恳请前辈们指点 |
geniustom
版主 ![]() ![]() ![]() ![]() ![]() 發表:100 回覆:303 積分:260 註冊:2003-01-03 發送簡訊給我 |
|
wameng
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
我會被 小Y123 給整死....呵呵... 在
原來的: for j:=0 to imageHeight-1 do begin for i:=0 to imageWidth-1 do begin if s[i,j]/max >0.2 then Data[k,j*imagewidth i-k*imagewidth]:=0.9 else Data[k,j*imagewidth i-k*imagewidth]:=0.1; end; 真搞不懂為何要減,當K=1,I=0 該整體值會變成 -16。 當然出錯! 因此改為...,就可正常運作。 E:= charedit.Text; num:=length(E ); memo1.Clear ; setlength(s,imagewidth,imageHeight); setLength(data,num,imagewidth*imageHeight); ....... ....... for j:=0 to imageHeight-1 do for i:=0 to imageWidth-1 do begin if s[i,j]/max >0.2 then Data[k,j*imagewidth i]:=0.9 else Data[k,j*imagewidth i]:=0.1; end; |
小丫123
初階會員 ![]() ![]() 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |