OLD | NEW |
---|---|
(Empty) | |
1 #include <math.h> | |
2 #include <string.h> | |
3 #include <jni.h> | |
4 #include <android/bitmap.h> | |
5 | |
6 #include "SkCanvas.h" | |
7 #include "SkData.h" | |
8 #include "SkGraphics.h" | |
9 #include "SkSurface.h" | |
10 #include "SkImage.h" | |
11 #include "SkStream.h" | |
12 #include "SkString.h" | |
13 #include "SkTime.h" | |
14 | |
15 extern "C" | |
16 JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv* env, | |
djsollen
2013/06/03 18:24:45
add a brief comment explaining what this method do
Zach Reizner
2013/06/03 22:54:25
Done.
| |
17 jobject thiz, jobject dstBitmap) | |
18 { | |
djsollen
2013/06/03 18:24:45
move to previous line
Zach Reizner
2013/06/03 22:54:25
Done.
| |
19 | |
20 // Grab the dst bitmap info and pixels | |
21 AndroidBitmapInfo dstInfo; | |
22 void* dstPixels; | |
23 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); | |
24 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); | |
25 | |
26 SkAutoGraphics ag; | |
Zach Reizner
2013/06/03 22:54:25
This was removed because repeated constructions/de
| |
27 SkString path("skhello.png"); | |
djsollen
2013/06/03 18:24:45
remove this unless you plan on drawing it.
Zach Reizner
2013/06/03 22:54:25
Done.
| |
28 SkString text("Skia is the Best!"); | |
djsollen
2013/06/03 18:24:45
define text where you use it not at the beginning
Zach Reizner
2013/06/03 22:54:25
Done.
| |
29 | |
30 // Setup | |
31 SkPaint paint; | |
djsollen
2013/06/03 18:24:45
same as above (define it closer to where it is use
Zach Reizner
2013/06/03 22:54:25
Done.
| |
32 paint.setAntiAlias(true); | |
33 paint.setTextSize(SkIntToScalar(30)); | |
34 paint.setTextAlign(SkPaint::kLeft_Align); | |
35 | |
36 SkImage::Info info = { | |
37 dstInfo.width, dstInfo.height, SkImage::kPMColor_ColorType, SkImage::kPr emul_AlphaType | |
38 }; | |
39 | |
40 // Create a surface and get its canvas | |
41 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | |
42 SkCanvas* canvas = surface->getCanvas(); | |
43 | |
44 // Draw something "interesting" | |
djsollen
2013/06/03 18:24:45
let's draw some more interesting stuff. You can pr
Zach Reizner
2013/06/03 22:54:25
Done.
| |
45 SkScalar fontHeight = paint.getFontSpacing(); | |
46 canvas->drawColor(SK_ColorWHITE); | |
47 canvas->drawText(text.c_str(), text.size(), | |
48 10, fontHeight, | |
49 paint); | |
50 | |
51 // Grab the pixels from the canvas | |
52 SkBitmap canvasBitmap; | |
djsollen
2013/06/03 18:24:45
you shouldn't need this at all.
Zach Reizner
2013/06/03 22:54:25
Done.
| |
53 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, dstInfo.width, dstInfo.h eight); | |
54 canvas->readPixels(&canvasBitmap, 0, 0); // Read from the top corner | |
55 | |
56 // Copy the pixels from Skia into the Java Bitmap | |
57 for (uint32_t row = 0; row < dstInfo.height; row++) | |
djsollen
2013/06/03 18:24:45
this isn't very efficient. We should just have our
Zach Reizner
2013/06/03 22:54:25
Done.
| |
58 { | |
59 void* dstRow = (char*)dstPixels + dstInfo.stride * row; | |
60 void* srcRow = canvasBitmap.getAddr(0, row); | |
61 memcpy(dstRow, srcRow, dstInfo.stride); | |
62 } | |
63 | |
64 // Unlock the dst | |
65 AndroidBitmap_unlockPixels(env, dstBitmap); | |
66 } | |
OLD | NEW |