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 17static void create_bitmap(SkBitmap* bitmap) { 18 const int W = 100; 19 const int H = 100; 20 bitmap->allocN32Pixels(W, H); 21 22 SkCanvas canvas(*bitmap); 23 canvas.drawColor(SK_ColorRED); 24 SkPaint paint; 25 paint.setColor(SK_ColorBLUE); 26 canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint); 27} 28 29class WritePixelsView : public Sample { 30 SkPath fPath; 31public: 32 WritePixelsView() {} 33 34protected: 35 SkString name() override { return SkString("WritePixels"); } 36 37 void onDrawContent(SkCanvas* canvas) override { 38 SkBitmap bitmap; 39 create_bitmap(&bitmap); 40 int x = bitmap.width() / 2; 41 int y = bitmap.height() / 2; 42 43 SkBitmap subset; 44 bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); 45 46 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 47 48 canvas->writePixels(bitmap, 0, 0); 49 canvas->writePixels(subset, 0, 0); 50 } 51 52private: 53 using INHERITED = Sample; 54}; 55 56////////////////////////////////////////////////////////////////////////////// 57 58DEF_SAMPLE( return new WritePixelsView(); ) 59