編輯:關於Android編程
基於淺談 Google Skia 圖形處理引擎和Skia Demo Build。 Skia是一個跨平台的圖形庫,目前使用在Android中,同樣也有PC版本,這裡測試一下以了解其內涵。
1.PC版本測試:
# 1.下載 Skia
git clone [email protected]:google/skia.git
# 2.切換到老版本 參考ubuntu 移植SKIA的日期進行回退
git reset --hard 0e2810be95d3f1aa95c341521d3f514eb9e9ebde
# 3.查看編譯幫助
$ make help
Targets:
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 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_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
顯示的是一張圖片如下:
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+suLK1LPM0PKjujwvcD4KPHA+LyogU2ltcGxlIHZlY3RvciBncmFwaGljcyBkZW1vIHV0aWxpemluZyBTa2lhIHRvb2xraXQuPC9wPgo8cD4gKiBBdXRob3JlZCBieSBKaW0gSHVhbmcgPGpzZXJ2LnR3QGdtYWlsLmNvbT48L3A+CjxwPiAqLzwvcD4KPHA+IDwvcD4KPHA+I2luY2x1ZGUg"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 := \
libskia
include $(BUILD_EXECUTABLE)
可以原封不動地將PC上的測試源碼編譯成適合Android的測試程序。將其放到/system/bin目錄下。如下執行:
$ cd sdcard
$ skia_test2
會在/sdcard目錄下同樣生成snapshot.png,傳到PC上查看和之前實驗效果一樣。以後會加入freetype和framebuffer。最終實現撇開Android系統來實現簡單圖形字體顯示。
效果如圖中藍框所框 0){ editText.setText(defaultText); } editText.setEnabled(isReadOnl
Windows Manager是一款窗口管理終端,可以遠程連接到Linux的X桌面進行管理,與服務器端產生一個session相互通信。最近在網上看見一個人在烏
本篇繼續來講自定義ViewGroup,給大家帶來一個實例:FlowLayout。何為FlowLayout,就是控件根據ViewGroup的寬,自動的往右添加,如果當前行剩
網上demo的效果:差不多應該是這樣的,但是容易出一些問題,比如你的圖片本身就是個圓角?又或者圖片太大,你想縮小顯示,但出現顯示內容不全?我想實現的效果是這樣的:http