Created
June 23, 2017 11:49
-
-
Save HalCanary/3f6867f2ec09f138f0488e7b95562771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment