关于在 ActionScript 3 位图中生成声音波形
我正在生成位图对象来显示加载声音的声音波形。位图为 1024x120,生成后我将其大小缩小到 655x120。我的问题是在任务管理器中加载位图的播放器变得 260MB 重。
我还添加了一些渐变,并将其缓存为位图,但如果删除此属性,大小不会有任何大差异。
我也可以尝试缩小它的大小,但我仍然认为位图会很大。
知道如何压缩或任何解决方案来解决这个问题吗?
谢谢
这是一些代码
这些是生成位图的函数的声音和位图设置。
public function generateBitmap(snd:Sound):void
{
samples = new ByteArray();
buffer = new BitmapData(1024, 120, false, backColor);
screen = new Bitmap(buffer);
rect = new Rectangle(0, 0, 1, 0);
var left:Number;
var right:Number;
screen.x = 0;
screen.y = 0;
screen.width = 655;
screen.height = 120;
buffer.fillRect( buffer.rect, backColor );
现在我正在做一些样本提取
var extract:Number = Math.floor ((snd.length / 1000) * 44100);
playingTime = snd.length;
ratio = playingTime / buffer.width;
var lng:Number = snd.extract(samples, extract);
samples.position = 0;
step = samples.length / 4096;
do
{
step-- ;
}
while ( step % 4 );
遵循位图的绘制方法。
for (var c:int = 0; c < 4096; c++)
{
rect.x = c / 4;
left = samples.readFloat() * 25;
right = samples.readFloat() * 25;
samples.position = c * step;
// left channel
if (left > 0)
{
rect.y = 30 - left;
rect.height = left;
}
else
{
rect.y = 30;
rect.height = -left;
}
buffer.fillRect( rect, leftChColor );
// right channel
if (right > 0)
{
rect.y = 80 - right;
rect.height = right;
}
else
{
rect.y = 80;
rect.height = -right;
}
buffer.fillRect( rect, rightChColor );
}
screen.width = screenWidth;
screen.height = screenHeight;
addChild( screen );
}
这是我使用的代码的参考。在播放器中没有我的东西的情况下进行了尝试,并为闪存播放器获得了 193MB 的 RAM。所以代码需要我猜代码需要改进。有什么想法或其他方法可以在不消耗这么多内存的情况下做同样的事情吗?
I am generating Bitmap object to show the sound waveform of a loaded sound. The bitmap is 1024x120 and after it has been generated I shrink its size to 655x120. My problem is the player that loads the bitmap in task manager becomes 260MB heavy.
I am also adding some gradients and I also cache it as bitmap, but if I remove this properties I dont get any big difference in size.
I also can try to small its size but still I think the bitmap will be big.
Any idea how to compress or whatever solution to solve this problem?
thanks
Here is some code
These are the sound and Bitmap settigns of the function that generate the bitmap.
public function generateBitmap(snd:Sound):void
{
samples = new ByteArray();
buffer = new BitmapData(1024, 120, false, backColor);
screen = new Bitmap(buffer);
rect = new Rectangle(0, 0, 1, 0);
var left:Number;
var right:Number;
screen.x = 0;
screen.y = 0;
screen.width = 655;
screen.height = 120;
buffer.fillRect( buffer.rect, backColor );
Now I am doing some samples extraction
var extract:Number = Math.floor ((snd.length / 1000) * 44100);
playingTime = snd.length;
ratio = playingTime / buffer.width;
var lng:Number = snd.extract(samples, extract);
samples.position = 0;
step = samples.length / 4096;
do
{
step-- ;
}
while ( step % 4 );
Follows the drawing method of the bitmap.
for (var c:int = 0; c < 4096; c++)
{
rect.x = c / 4;
left = samples.readFloat() * 25;
right = samples.readFloat() * 25;
samples.position = c * step;
// left channel
if (left > 0)
{
rect.y = 30 - left;
rect.height = left;
}
else
{
rect.y = 30;
rect.height = -left;
}
buffer.fillRect( rect, leftChColor );
// right channel
if (right > 0)
{
rect.y = 80 - right;
rect.height = right;
}
else
{
rect.y = 80;
rect.height = -right;
}
buffer.fillRect( rect, rightChColor );
}
screen.width = screenWidth;
screen.height = screenHeight;
addChild( screen );
}
Here is a reference of the code I have used. Tried it without my stuff in the player and get 193MB of RAM just for the flash player. So the code needs I guess the code needs refinement. Any idea or othere method to do the same stuff without eating so much RAM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此行之前:
添加:
Before this line:
Add: