基于淺談 Google Skia 圖形處理引擎Skia Demo Build。 Skia是一个跨平台的图形库,目前使用在Android中,同样也有PC版本,这里测试一下以了解其内涵。

1.PC版本测试:

首先:sudo apt-get install libfreetype6-dev libpng-dev

# 1.下载 Skia git clone git@github.com:google/skia.git# 2.切换到老版本 参考ubuntu 移植SKIA的日期进行回退git reset --hard 0e2810be95d3f1aa95c341521d3f514eb9e9ebde# 注:不使用git的话,也可以点击skia_0e2810b下载# 3.查看编译帮助$ make helpTargets:    : out/libskia.a    bench: out/bench/bench    gm: out/gm/gm    skimage: out/tools/skimage    skhello: out/tools/skhello    tests: out/tests/tests    clean: removes entire out/ directory    help: this textOptions: (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_PDF_SUPPORT=false to disable the pdf generation backend# 3.进行编译$ make SKIA_BUILD_FOR=linux# 4.将Skia Demo Build的例子保存为test-skia.c。# 5.编译测试程序$ 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.a \        -lpng -lpthread -lfreetype -g# 运行$ ./test-skia# 查看测试结果$ eog snapshot.png

显示的是一张图片如下:

 

测试程序:

/* 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 to// 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 a// device (bitmap).  This includes 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. The// transformed geometry is clipped by the intersection of all of the// clips in the stack.SkCanvas canvas(bitmap);// SkPaint class holds the style and color information about how to// 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.在Android中测试

写了一个Android.mk内容如下:

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 := \    libskiainclude $(BUILD_EXECUTABLE)

可以原封不动地将PC上的测试源码编译成适合Android的测试程序。将其放到/system/bin目录下。如下执行:

$ cd sdcard

$ skia_test2

会在/sdcard目录下同样生成snapshot.png,传到PC上查看和之前实验效果一样。以后会加入freetypeframebuffer。最终实现撇开Android系统来实现简单图形字体显示。

如果编译最新版本的skia,参考这里How to check out and build Skia on Linux。


更:

-libpng如果有问题可以替换为`pkg-config libpng --libs`

Skia & FreeType Android 2D Graphics Essentials

很好的文章。


更多相关文章

  1. Android(安卓)Toolchain与Bionic Libc
  2. Android(安卓)NDK 教程 - NDK环境配置和 Android(安卓)Studio 中
  3. Android(安卓)中Preferences的使用!
  4. android ksoap2 中把XML(DataSet) 当做参数传递
  5. 如何制作Jar包并在android中调用jar包
  6. 搭建Android开发环境写第一个Hello World程序1
  7. Android终端命令执行编译命令()
  8. 【Android】MTK Android(安卓)编译命令
  9. android TabHost(选项卡)的使用方法

随机推荐

  1. 腾讯轻听模仿流水账(1):16.11.25
  2. Android Studio 视图解析
  3. 将Activity打包成jar文件
  4. Android Application Task Activities的
  5. android 实用javamail发送邮件(非系统自带
  6. arcgis for android 学习 - (7) 在真机上
  7. Android4.0和Android4.1全屏方法
  8. Android 4.2 输入流程分析
  9. android5.1 取消录制屏幕跳出的权限对话
  10. Android(安卓)SDK 使用技巧