Android NDK中SKIA无法画出文字

张雷 发布于 2012/02/28 22:37
阅读 2K+
收藏 0
我在Windows下,搭建了cygwin
使用的NDK是android-ndk-r6,
使用的Android SDK版本是2.3.1
Android源码使用的是git下载的:git clone http://android.git.kernel.org/...其中包括了external/skia
然后在模拟器中把libskia.so, libskiagl.so,libjnigraphics.so和libandroid_runtime.so提取了出来,
放在了NDK下的platforms\android-9\arch-arm\usr\lib中
我的mk文件是这样的:
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

MY_ANDROID_SOURCE=/cygdrive/d/Android_Source

LOCAL_MODULE := libSkiaDemo
LOCAL_CPP_EXTENSION := .cpp
LOCAL_CXXFLAGS :=

LOCAL_C_INCLUDES := $(MY_ANDROID_SOURCE)/frameworks/base/core/jni/android/graphics \
$(MY_ANDROID_SOURCE)/external/skia/include/core \
$(MY_ANDROID_SOURCE)/external/skia/include/images \
$(MY_ANDROID_SOURCE)/external/skia/include/config \
$(MY_ANDROID_SOURCE)/frameworks/base/include \
$(MY_ANDROID_SOURCE)/system/core/include

LOCAL_SRC_FILES := SkiaDemoJni.cpp

LOCAL_LDLIBS := -llog -lsgl -lskia -lskiagl -ljnigraphics -landroid_runtime \
-L$(MY_ANDROID_SOURCE)/out/target/product/generic/system/lib/

include $(BUILD_SHARED_LIBRARY) 
NDK中的画字符的代码是这样的:
void Java_com_whtr_example_skiademo_SkiaView_renderText(JNIEnv *env, jobject thizz, jobject canvas)
{
SkCanvas* canv = GraphicsJNI::getNativeCanvas(env, canvas);
if (!canv)
{
__android_log_print(ANDROID_LOG_DEBUG, "bug", "canvas is null ");
//LOGE("!canv");
return;
}
__android_log_print(ANDROID_LOG_DEBUG, "bug", "canvas is NOT null ");

SkPaint paint;
char text[256] = {0};
paint.setColor(SK_ColorBLACK);
strcpy(text, "Hello");
canv->drawText(text, strlen(text), 20, 20, paint);

strcpy(text, "what when");
paint.setAntiAlias(true);
canv->drawText(text, strlen(text), 20, 60, paint);

strcpy(text, "oh, god");
paint.setSubpixelText(true);
canv->drawText(text, strlen(text), 20, 100, paint);

}

然后在cygwin中用$NDK/ndk-build编译并且运行,结果是画不出来。然后我又试了画线和画矩形,是可以画出来的。

大家知道是什么原因吗?

我在下载源码的时候并没有选择那个版本,只是写了路径,如:
git clone http://android.git.kernel.org/framework/base,跟版本有关系吗?
加载中
0
yajun
yajun
skia版本不完整
0
r
renzy
libskia.so与android版本有关
0
idoz
idoz
Android has the advantage of controlling the entire operating system graphics layer. Skia's font layer implements all text rendering for the Android system, so all text looks consistent. However, we wanted to match the host OS's look and feel. This means using native text rendering routines so that, for example, we can get  ClearType on Windows.

To solve this problem, we create a wrapper around Skia's SkDevice (an object representing a low-level drawing surface) which we call PlatformDevice. The object is both a bitmap in main memory that Skia can draw into, and a "Device Independent Bitmap" that the Windows GDI layer can draw into. Lines, images, and patters are all drawn by Skia into this bitmap, while text is drawn directly by Windows. As part of our porting efforts, we are currently working on creating similar abstractions for OS X and Linux.
0
idoz
idoz

在windows 下它使用gdi 绘制文本的。

while text is drawn directly by Windows. 

详细请参考:http://blog.chromium.org/2008/10/graphics-in-google-chrome.html

返回顶部
顶部