|
|
发表于 2010-9-18 21:42:58
|
显示全部楼层
畫圖的部份解決了, 但條碼顯示不正確 ..... 仍然算是未解決
畫圖的部份說明一下
1.所有的 brush.Style := bsClear; 都被我 remark 起來, 因為聽說有 bug, 跟 Delphi 呈現效果不同
2.bmpMem 在一開始就決定其 Width 及 Height, 不要在 for loop 中追加改變它的值, 我發現只要動態去改變其值, 整個 Canvas 就變黑了 (又是一個跟 Delphi 不一樣的地方)
3.計算條碼間距的 Function 有問題, 算出的間距都太小, 條碼都結在一塊, 所以我加了個
4.對計算條碼間距的 Function 內部處理不熟悉, 只是聽說 Lazarus 有些變量 type 跟 Delphi 內部存放的 byte 數不同, 或許這是造成計算值有問題的原因
procedure TLazBarcode.DrawBarcode;
var tCenter,i,xadd, x, y:Integer;
lt : TFlatLines;
fwidth, fheight,wBorder:integer;
a,b,c,d, orgin : TPoint;
bmpMem:TBitmap;
Rect:TRect;
str:String;
begin
bmpMem:= TBitmap.Create;
try
with bmpMem.Canvas do
begin
Font.Assign(self.Font);
wBorder := TextWidth('1')*2 + fBorderWidth div 2;
case CodeType of
EAN13,EAN8,UPC_A,UPC_EODD,UPC_EVEN:
xadd := wBorder
else
xadd := fBorderWidth;
end;
orgin.x := xadd;//Left;
orgin.y := fBarTop;//Top 0;
bmpMem.Width := 218; //xadd;
bmpMem.Height := 46; //fBarHeight+fBarTop;
//brush.Style := bsClear;
Brush.Color := Color;
FillRect(ClipRect);
Pen.Width := 1;
for i:=1 to Length(data) do
begin
OneBarProps(Data,fWidth,lt); Pen.Color := fBarColor;//clWhite;
//brush.Style := bsClear;
Brush.Color := Color;
if (lt = ltBlack) or (lt = ltBlack_half) then
Brush.Color := fBarColor;//clBlack
if lt = ltBlack_half then
fheight := bmpMem.Height * 2 div 5
else
fheight := bmpMem.Height;
GetABCED(a,b,c,d,orgin,xadd, ,fHeight);
Polygon([a,b,c,d]);
xadd := xadd + fwidth;
//bmpMem.Width := xadd;
end;//结束画直线
Brush.Color := Color;
Rect := ClipRect;
Rect.Bottom := fBarTop;
FillRect(Rect);
Rect := ClipRect;
Rect.Right := fBorderWidth;
FillRect(Rect);
if fShowText then
begin
if (CodeType = EAN13)or(CodeType = EAN8)or
(CodeType = UPC_A)or(CodeType = UPC_EODD)or
(CodeType = UPC_EVEN) then
begin
//bmpMem.Height := bmpMem.Height + TextHeight('A') div 2;
//bmpMem.Width := xadd + wBorder;
case CodeType of
EAN13 : DrawEAN13Text(bmpMem.Canvas,bmpMem.Width,wBorder);
EAN8 : DrawEAN8Text(bmpMem.Canvas,bmpMem.Width,wBorder);
UPC_A : DrawUPC_AText(bmpMem.Canvas,bmpMem.Width,wBorder);
else //UPC_EODD,UPC_EVEN;
DrawUPC_EText(bmpMem.Canvas,bmpMem.Width,wBorder);
end;
end
else
begin
//bmpMem.Height := bmpMem.Height + TextHeight('A');
//bmpMem.Width := xadd + fBorderWidth;
if bmpMem.Width > TextWidth(BarText) then
tCenter:=(bmpMem.width-TextWidth(BarText))div 2
else
tCenter:=0;
case CodeType of
Code93Ext,
Code39Ext:Str := Copy(BarText,3,Length(BarText)-2);
else
Str := BarText;
end;
TextOut(tCenter, fBarHeight+fBarTop, Str);
end;
end
else
begin
//bmpMem.Width := xadd + fBorderWidth;
Rect := ClipRect;
Rect.Top := Rect.Bottom - fBarTop;
FillRect(Rect);
end;
case fRotateType of
raNone:fBitmap.Assign(bmpMem);
ra270:begin
fBitmap.width := bmpMem.Height;
fBitmap.Height := bmpMem.Width;
for x:=0 to bmpMem.Height-1 do
for y:=0 to bmpMem.Width-1 do
fBitmap.canvas.Pixels[(-x+bmpMem.Height),y]:=Pixels[y,x];
end;
ra180:begin
fBitmap.width := bmpMem.Width;
fBitmap.Height := bmpMem.Height;
for x:=0 to bmpMem.Height-1 do
for y:=0 to bmpMem.Width-1 do
fBitmap.canvas.Pixels[(bmpMem.Width-y),(bmpMem.Height-x)]:=Pixels[y,x];
end;
ra090:begin
fBitmap.width := bmpMem.Height;
fBitmap.Height := bmpMem.Width;
for x:=0 to bmpMem.Height-1 do
for y:=0 to bmpMem.Width-1 do
fBitmap.canvas.Pixels[x,(bmpMem.Width-y)]:=Pixels[y,x];
end;
end;
end;
finally
bmpMem.free;
end;
end; |
|