In this case, the image is an essential part of the UI rendering for custom painting in Android and j2s.
If you have played mobile games in the j2s environment, especially those that pass through the horizontal version, you can generate an image object from the resource file and use the damn graphics. drawimage (image, Int, Int, INT) and other methods to draw the image to the specified position. Although Android is more beautiful than N, this kind of thing cannot be spared-its canvas. drawbitmap (bitmap, Int, Int, paint) is used for this purpose.
At first glance, there seems to be no difference between the two things, at least in terms of plotting. But there are no two leaves in the world, not to mention two classes. Taking a closer look, there is a big difference in the construction of the image and bitmap objects.
First, we can see that the image class does not have open constructors, but there are a lot of static creatimage () methods, the N-plus overload allows you to create an image object from the file name, data stream, the constructed image object, or even the byte array. It is quite convenient to create it. But Android does not. It's a bitmap class. If you want to construct it from a resource file, it can be very troublesome. Please refer Code : Resources R = Getresources ();
Bitmap Board = Bitmap. createbitmap ( 240 , 240 , Bitmap. config. argb_8888 );
Canvas C = New Canvas (Board );
Drawable tempboard = R. getdrawable (R. drawable. Board );
Tempboard. setbounds ( 0 , 0 , 240 , 240 );
Tempboard. Draw (C );
This code is called in the activity. Resources only indicates that our bitmap is constructed from the resource file, and there are no other special points. As you can see, bitmap is the same as image, and does not get its instance through the constructor but through the static method (this is the same as the image class ). Bitmap. createbitmap (INT, Int, bitmap. config) method only creates an empty bitmap object (This NULL is not a null pointer, some are similar to the Null String "", at least I understand it ), then, the bitmap object is passed through the construction method of the canvas class (this is the canvas class of Android, not the j2's) and then drawable. the draw (canvas) method draws the drawable object (which is very close to the resource file) to the canvas, so that bitmap can be connected to image files like PNG in the resource folder drawable ......
This process is very troublesome. It is nice to say that bitmap is difficult to climb. What you can't say is to take off your pants and fart. Although it is not very complex, it is estimated that only Google knows why it is a one-step solution.
The instance has been created and initialized, so it can be used. bitmap is flexible in usage and can be used in many places. It is similar to the image usage of j2s, this is quite satisfactory.
The comparison of the two classes is now here. Next time we will compare the differences between the two classes in the response key input and the touch screen events between the two classes.
Thank you!