Java位图合成如何
我正在将 AS3 (Flash) 应用程序移植到 Java Android。我需要一个与这个原型等效的函数: copyPixels(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, alphaBitmapData:BitmapData = null, alphaPoint:Point = null, mergeAlpha:Boolean = false):void
重要的参数是 SourceBitmap、SourceRect、DestPoint 和 MergeAlpha,我没有需要其他参数。现在我在 Java 中使用 Bitmap 类,是否有可能使用 Bitmap 类提供这样一个函数,该函数相当快地克服 Android Java 性能不佳的问题?
也许我应该使用 BufferedImage 或其他东西,但我迷失了,因为 Java 有很多图像/位图,无论执行类似任务的类,而 AS3 只有 2 个。我还没有找到一些代码可以在不诉诸某些方法的情况下完成我想要的任务由于 Java Android 的性能问题,我想避免使用 Canvas 类的形式。 Bitmap 类中有 CopyPixels 函数,但据我了解,它不会合成 alpha 值。我确信某个地方有一些代码可以完成我所做的事情,并希望我不必重新发明轮子。
感谢您的回答/评论。
I'm porting an AS3 (Flash) application to Java Android. And I need an equivalent function to this prototype:
copyPixels(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, alphaBitmapData:BitmapData = null, alphaPoint:Point = null, mergeAlpha:Boolean = false):void
The important parameters are SourceBitmap, SourceRect, DestPoint and MergeAlpha, I don't need the other parameters. Right now I'm using Bitmap class in Java, is it possible to have such a function with Bitmap class that is reasonably fast to overcome Android Java poor performance?
Maybe I should use BufferedImage or something else but I'm lost because Java has a lot of Image/Bitmap whatever Class that performs similar duty while AS3 only have 2. I haven't found some code that does what I want without resorting to some form of Canvas class which I want to avoid because of performance issues with Java Android. There is CopyPixels function in Bitmap class but from what I understand it does not composite alpha values. I'm sure there is some code somewhere that does what I do and hope I won't have to reinvent the wheel.
Thanks for answers/comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 android.graphics.Bitmap 类。 Android 画布实际上非常高效。它只是一个包装器,允许您在位图上进行基本绘图。如果您查看一些 openGL 示例,您会发现使用 canvas 绘图通常比 Java 中的 openGL 更快。性能问题是什么?也许SO可以帮助解决这些问题。
此外,您还可以通过迭代位图中的像素并自己混合颜色来自己完成此操作。这不是很困难,但实际上,那里的性能与 Canvas 类没有太大不同。
You should be using the android.graphics.Bitmap class. The Android canvas is actually very efficient. It is just a wrapper that allows you to do basic drawing on a bitmap. If you take a look at some of the openGL examples, drawing is usually faster using canvas than openGL in Java. What were the performance issues? Maybe SO can help solve those problems.
Also, you could do it yourself by iterating through the pixels in the bitmap and blending colors yourself. It's not very difficult, but really the performance there is not going to be much different than the Canvas class.