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.
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.