Skip to content
Search

Skia

lastmod 2022-05-06created 2016-06-235 edits

The Skia Graphics Engine is a compact open source graphics library written in C++. It was originally developed by Skia Inc., which was subsequently acquired by Google in 2005, who then released the software as open source licensed under the New BSD License free software license.

skia is also included in Google's Android phone operating system, and was first released publicly with the recent release of the Chrome browser. It is built on software Google acquired in 2005. skia reportedly means "shadow" in Greek.

Why Skia?

  • GDI is not full-featured enough for SVG, Canvas, and complex UI processing.
  • SKIA can be modified by google to fit its needs.
  • There was already a high-quality Webkit/Canvas port to Skia.
  • GDI+ is no longer developed by MS, and is slower than SKIA for most operations.
  • GDI+ text rendering is not compatible with GDI text rendering.

Sample example

#include "SkBitmap.h"
#include "SkDevice.h"
#include "SkRect.h"

void CMainFrame::OnSkiaTestskia()
{
    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
    bitmap.allocPixels();
    SkDevice device(bitmap);
    SkCanvas canvas(&device);

    SkPaint paint;
    SkRect r;

    paint.setARGB(255,255,255,255);
    r.set(10,10,100,100);
    canvas.drawRect(r, paint);

    paint.setARGB(128, 0, 0, 255);
    r.set(50, 50, 150, 150);
    canvas.drawRect(r, paint);

    {
    SkAutoLockPixels image_lock(bitmap);
    CxImage image;
    image.CreateFromArray((BYTE*)bitmap.getPixels(), bitmap.width(), bitmap.height(), 32, bitmap.rowBytes(), false);
    image.Save("_skia.png", CXIMAGE_FORMAT_PNG);
    }

    CWinApp *app = AfxGetApp(); ASSERT(app);
    app->OpenDocumentFile("_skia.png");
}

How to write Android Native code

Android uses the Skia graphics library.

  1. The Skia library is not provided by the NDK.
  2. To build code that uses the Skia library, you must either get and build the full Android source, or get the Skia library (it is open source) and link it separately.
  3. Add the Skia header files to your code.
  4. Add the library locations to the Android mk file as follows (when building from the full Android source).
LOCAL_C_INCLUDES := \
 external/skia/include/core \
 external/skia/include/effects \
 external/skia/include/images \
 external/skia/include/utils \

See also

Favorite site

author Zer0 sitemap