Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SkCanvas.h"
- #include "SkGraphics.h"
- #include "SkImageEncoder.h"
- #include "SkString.h"
- static void draw(SkCanvas* canvas) {
- canvas->drawColor(SkColorSetARGB(255, 101, 33, 131));
- SkPaint paint;
- //Set Text ARGB Color
- paint.setARGB(255, 255, 255, 255);
- //Turn AntiAliasing On
- paint.setAntiAlias(true);
- //Set Text Size
- paint.setTextSize(SkIntToScalar(30));
- //Text X, Y Position Varibles
- SkScalar x = 80;
- SkScalar y = 60;
- //Set Text To Draw
- SkString text("Hello, World");
- canvas->drawText(text.c_str(), text.size(), x, y, paint);
- //Set Style and Stroke Width
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(10);
- //Draw A Rectangle
- SkRect rect;
- paint.setARGB(255, 0, 0, 0);
- //Left, Top, Right, Bottom
- rect.set(50, 100, 200, 200);
- canvas->drawRoundRect(rect, 20, 20, paint);
- //Draw A Line
- canvas->drawLine(10, 300, 300, 300, paint);
- //Draw Circle (X, Y, Size, Paint)
- canvas->drawCircle(100, 400, 50, paint);
- }
- int main (int argc, char * const argv[]) {
- SkAutoGraphics ag;
- //Set Image Width & Height
- SkScalar width = 800;
- SkScalar height = 600;
- SkBitmap bitmap;
- bitmap.allocN32Pixels(width, height);
- //Create Canvas
- SkCanvas canvas(bitmap);
- draw(&canvas);
- //Output filename
- SkString path("skhello.png");
- SkFILEWStream file(path.c_str());
- SkASSERT(file.isValid());
- SkAssertResult(SkEncodeImage(&file, bitmap, SkEncodedImageFormat::kPNG, 100));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement