SampleWritePixels.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2011 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkBitmap.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkPath.h"
  10. #include "include/core/SkRegion.h"
  11. #include "include/core/SkShader.h"
  12. #include "include/effects/SkCornerPathEffect.h"
  13. #include "include/effects/SkGradientShader.h"
  14. #include "samplecode/Sample.h"
  15. #include "src/utils/SkUTF.h"
  16. static void create_bitmap(SkBitmap* bitmap) {
  17. const int W = 100;
  18. const int H = 100;
  19. bitmap->allocN32Pixels(W, H);
  20. SkCanvas canvas(*bitmap);
  21. canvas.drawColor(SK_ColorRED);
  22. SkPaint paint;
  23. paint.setColor(SK_ColorBLUE);
  24. canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
  25. }
  26. class WritePixelsView : public Sample {
  27. SkPath fPath;
  28. public:
  29. WritePixelsView() {}
  30. protected:
  31. virtual SkString name() { return SkString("WritePixels"); }
  32. virtual void onDrawContent(SkCanvas* canvas) {
  33. SkBitmap bitmap;
  34. create_bitmap(&bitmap);
  35. int x = bitmap.width() / 2;
  36. int y = bitmap.height() / 2;
  37. SkBitmap subset;
  38. bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
  39. canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
  40. canvas->writePixels(bitmap, 0, 0);
  41. canvas->writePixels(subset, 0, 0);
  42. }
  43. private:
  44. typedef Sample INHERITED;
  45. };
  46. //////////////////////////////////////////////////////////////////////////////
  47. DEF_SAMPLE( return new WritePixelsView(); )