Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include "SkCanvas.h"
  2. #include "SkGraphics.h"
  3. #include "SkImageEncoder.h"
  4. #include "SkString.h"
  5.  
  6. static void draw(SkCanvas* canvas) {
  7. canvas->drawColor(SkColorSetARGB(255, 101, 33, 131));
  8.  
  9. SkPaint paint;
  10.  
  11. //Set Text ARGB Color
  12. paint.setARGB(255, 255, 255, 255);
  13.  
  14. //Turn AntiAliasing On
  15. paint.setAntiAlias(true);
  16.  
  17. //Set Text Size
  18. paint.setTextSize(SkIntToScalar(30));
  19. //Text X, Y Position Varibles
  20.  
  21. SkScalar x = 80;
  22. SkScalar y = 60;
  23. //Set Text To Draw
  24. SkString text("Hello, World");
  25.  
  26. canvas->drawText(text.c_str(), text.size(), x, y, paint);
  27.  
  28. //Set Style and Stroke Width
  29. paint.setStyle(SkPaint::kStroke_Style);
  30. paint.setStrokeWidth(10);
  31.  
  32. //Draw A Rectangle
  33. SkRect rect;
  34. paint.setARGB(255, 0, 0, 0);
  35. //Left, Top, Right, Bottom
  36. rect.set(50, 100, 200, 200);
  37. canvas->drawRoundRect(rect, 20, 20, paint);
  38.  
  39. //Draw A Line
  40. canvas->drawLine(10, 300, 300, 300, paint);
  41.  
  42. //Draw Circle (X, Y, Size, Paint)
  43. canvas->drawCircle(100, 400, 50, paint);
  44. }
  45.  
  46. int main (int argc, char * const argv[]) {
  47. SkAutoGraphics ag;
  48.  
  49. //Set Image Width & Height
  50. SkScalar width = 800;
  51. SkScalar height = 600;
  52. SkBitmap bitmap;
  53. bitmap.allocN32Pixels(width, height);
  54.  
  55. //Create Canvas
  56. SkCanvas canvas(bitmap);
  57. draw(&canvas);
  58.  
  59. //Output filename
  60. SkString path("skhello.png");
  61. SkFILEWStream file(path.c_str());
  62. SkASSERT(file.isValid());
  63. SkAssertResult(SkEncodeImage(&file, bitmap, SkEncodedImageFormat::kPNG, 100));
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement