skia in ndk SkImageEncoder::EncodeFile failing

232 views
Skip to first unread message

Sarim Khan

unread,
Dec 20, 2012, 7:19:23 AM12/20/12
to skia-d...@googlegroups.com
Hello,
I'm using android ndk to run a simple skia example but it's failing.

My Code: 

int drawnow () {

    //
    SkAutoGraphics ag;

    //Output filename
    SkString path("/data/local/tmp/skhello.png");

    //Set Text To Draw
    SkString text("Hydra v0.0.1a");

    SkPaint paint;

    //Set Text ARGB Color
    paint.setARGB(255, 255, 255, 255);

    Turn AntiAliasing On
paint.setAntiAlias(true);
    paint.setLCDRenderText(true);
    paint.setTypeface(SkTypeface::CreateFromName("DroidSans", SkTypeface::kNormal));

    //Set Text Size
    paint.setTextSize(SkIntToScalar(40));

    //Set Image Width & Height
    int width = 500;
    int height = 600;

    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
    bitmap.allocPixels();

    //Create Canvas
    SkCanvas canvas(new SkDevice(bitmap));
    canvas.drawARGB(255, 25, 25, 25);

    //Text X, Y Position Varibles
    int x = 80;
    int y = 60;

    //canvas.drawText(text.c_str(), text.size(), x, y, paint);

    //Set Style and Stroke Width
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(3);

    //Draw A Rectangle
    SkRect rect;
    paint.setARGB(255, 255, 255, 255);
    //Left, Top, Right, Bottom
    rect.set(50, 100, 200, 200);
    canvas.drawRoundRect(rect, 20, 20, paint);

    canvas.drawOval(rect, paint);

    //Draw A Line
    canvas.drawLine(10, 300, 300, 300, paint);

    //Draw Circle (X, Y, Size, Paint)
    canvas.drawCircle(100, 400, 50, paint);

    //Same Image  (file, bitmap, image_type, quality)
    bool success = SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);

    return success ;
}

 the drawnow function returns "false" and the output file /data/local/tmp/skhello.png is not created also. I'm very new to skia and cant figure how to make it work. Is There any SkError class or any other way to capture error ? Where is the error happening ?
no error is shown is logcat.
i'm using android ics 4.0.4 and linking against the /system/lib/libskia.so (builtin)

Derek Sollenberger

unread,
Dec 20, 2012, 11:41:51 AM12/20/12
to skia-d...@googlegroups.com
You will need to build your own copy of Skia (and statically link it) and not rely on the one already installed on the system as your headers won't match up with what the lib provides.  



--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/6SsDx4c4MNwJ.
To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/skia-discuss?hl=en.

Reply all
Reply to author
Forward
0 new messages