所以,我正在使用 Haxe 和 OpenFL 为手机制作这个应用程序。我有一个很长的文本,我从一个文本文件中加载它,并将它放入一个非常高的TextField
. Bitmap
但是,由于性能问题,我想将其转换为。
然而,再一次,从文本字段中绘制的非常高Bitmap
的内容只是显示空白(可能是数据太多?),所以我决定将位图数据拆分为“页面”位图,用户可以在屏幕上滑动。
当我添加要显示的第一个“页面”时,它确实如此。但其余的“页面”只是显示为空白图像。这是我的代码:
images = new Array();
var contentHeight:Float = 560;
field = new TextField();
var fieldFont = Assets.getFont("fonts/Kreon-Regular.ttf");
var format:TextFormat = new TextFormat(fieldFont.fontName, 26 /*currentZoom*/, 0xffffff);// 0x4F4F4F);
format.align = TextFormatAlign.LEFT;
field.defaultTextFormat = format;
var fieldWidth:Float = 410;
field.embedFonts = true;
field.text = fullText;
field.selectable = false;
field.wordWrap = true;
field.border = false;
field.autoSize = TextFieldAutoSize.LEFT;
field.width = fieldWidth;
//field.x = 0;
//addChild(field);
//loop through lines, if line within reach, increase clip height, else make new bd
var clipY:Float = 0;
var clipHeight:Float = 0;
trace(field.numLines);
var h_:Float = field.getLineMetrics(0).height;
var bd:BitmapData;
var mainBd:BitmapData = new BitmapData(Std.int(field.width), Std.int(field.height), true, 0x00000000);
mainBd.draw(field);
for (i in 0... field.numLines)
{
try {
h_ = field.getLineMetrics(i).height+0.2;
} catch (e:Dynamic) {}
if (clipHeight < contentHeight + h_)//line can be accomodated
{
clipHeight += h_;
}
else { //can't be accomodated, do clipping
bd = new BitmapData(Std.int(field.width), Std.int(clipHeight + 5), true, 0x00000000);
trace("clip: clipY:" + clipY + " height:" + clipHeight);
bd.copyPixels(mainBd, new Rectangle(0, clipY, field.width, clipHeight), new Point(0, clipY));
//bd.draw(field, new Matrix(), new ColorTransform(), BlendMode.NORMAL, new Rectangle(0, clipY, field.width, clipHeight), true);
images.push(new Bitmap(bd, PixelSnapping.AUTO, true));
clipY += clipHeight;
clipHeight = 0;
}
}
addChild(images[1]);