Android graphics library Skia (I)-generate PNG images through basic testing
Based on the zookeeper Google Skia processing engine and Skia Demo Build. Skia is a cross-platform graphics library. It is currently used in Android and also has a PC version. Here we will test it to understand its meaning.
1. PC version test:
#1. Download Skia
Git clone git@github.com: google/skia. git
#2. Switch to the old version and refer to the date on which the SKIA is transplanted in ubuntu for rollback.
Git reset -- hard 0e2810be95d3f1aa95c341521d3f514eb9e9ebde
#3. View compilation help
$ Make help
Targets:
: Out/libskia.
Timeout: out/timeout
Gm: out/gm
Skimage: out/tools/skimage
Skhello: out/tools/skhello
Tests: out/tests
Clean: removes entire out/directory
Help: this text
Options: (after make, or in bash shell)
SKIA_DEBUG = true for debug build
SKIA_SCALAR = fixed for fixed-point build
SKIA_BUILD_FOR = mac for mac build (e.g. CG for image decoding)
Skia_assist_support = false to disable the pdf generation backend
#3. Compile
$ Make SKIA_BUILD_FOR = linux
#4. Save the example of Skia Demo Build as a test-skia.c.
#5. Compile the test program
$ G ++ \
-I./include \
-I./include/core \
-I./include/images \
-I./include/config \
-Wall-o test-skia test-skia.c \
Out/src/images/SkImageDecoder_libpng.o out/libskia. \
-Lpng-lpthread-lfreetype-g
# Run
$./Test-skia
# View test results
$ Eog snapshot.png
An image is shown as follows:
Test procedure:
/* Simple vector graphics demo utilizing Skia toolkit.
* Authored by Jim Huang
*/
# Include "SkBitmap. h"
# Include "SkDevice. h"
# Include "SkPaint. h"
# Include "SkRect. h"
# Include "SkImageEncoder. h"
Int main ()
{
// Declare a raster bitmap, which has an integer width and height,
// And a format (config), and a pointer to the actual pixels.
// Bitmaps can be drawn into a SkCanvas, but they are also used
// Specify the target of a SkCanvas 'Drawing operations.
SkBitmap bitmap;
Bitmap. setConfig (SkBitmap: kARGB_8888_Config, 200,200 );
Bitmap. allocPixels ();
// A Canvas encapsulates all of the state about drawing into
// Device (bitmap). This includes des a reference to the device itself,
// And a stack of matrix/clip values. For any given draw call (e.g.
// DrawRect), the geometry of the object being drawn is transformed
// By the concatenation of all the matrices in the stack.
// Transformed geometry is clipped by the intersection of all of
// Clips in the stack.
SkCanvas canvas (bitmap );
// SkPaint class holds the style and color information about how
// Draw geometries, text and bitmaps.
SkPaint paint;
// SkIRect holds four 32 bit integer coordinates for a rectangle.
SkRect r;
Paint. setARGB (255,255, 0, 0 );
R. set (25, 25,145,145 );
Canvas. drawRect (r, paint);/** Draw the specified rectangle using
The specified paint. The rectangle
Will be filled or stroked based on
The Style in the paint .*/
Paint. setARGB (255, 0,255, 0 );
R. offset (20, 20 );
Canvas. drawRect (r, paint );
Paint. setARGB (255, 0, 0,255 );
R. offset (20, 20 );
Canvas. drawRect (r, paint );
// SkImageEncoder is the base class for encoding compressed images
// From a specific SkBitmap.
SkImageEncoder: EncodeFile ("snapshot.png", bitmap,
SkImageEncoder: kPNG_Type,
/* Quality ranges from 0 .. 100 */100 );
Return 0;
}
2. Test in Android
The content of Android. mk is as follows:
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_MODULE_TAGS: = optional
LOCAL_MODULE: = skia_test2
# Can't use 'local _ SRC_FILES: = $ (call all-subdir-cpp-files )'
LOCAL_SRC_FILES: = skia_test2.cpp
LOCAL_C_INCLUDES: = \
External/skia/include/core /\
External/skia/include/images/
LOCAL_SHARED_LIBRARIES: = \
Libskia
Include $ (BUILD_EXECUTABLE)
The test source code on the PC can be compiled as a test program suitable for Android. Put it in the/system/bin directory. Run the following command:
$ Cd sdcard
$ Skia_test2
Snapshot.png will be generated in the same sample under the/sdcarddirectory and uploaded to the PC to view the same effect as the previous experiment. Freetype and framebuffer will be added later. Finally, the Android system is used to display simple graphic fonts.