2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
2011-07-27 18:21:37 +00:00
|
|
|
|
|
|
|
static void create_bitmap(SkBitmap* bitmap) {
|
|
|
|
const int W = 100;
|
|
|
|
const int H = 100;
|
2014-02-17 02:55:57 +00:00
|
|
|
bitmap->allocN32Pixels(W, H);
|
2011-07-27 18:21:37 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(*bitmap);
|
|
|
|
canvas.drawColor(SK_ColorRED);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
|
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class WritePixelsView : public Sample {
|
2011-07-27 18:21:37 +00:00
|
|
|
SkPath fPath;
|
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
WritePixelsView() {}
|
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
virtual SkString name() { return SkString("WritePixels"); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
create_bitmap(&bitmap);
|
|
|
|
int x = bitmap.width() / 2;
|
|
|
|
int y = bitmap.height() / 2;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
SkBitmap subset;
|
|
|
|
bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
|
|
|
|
canvas->writePixels(bitmap, 0, 0);
|
|
|
|
canvas->writePixels(subset, 0, 0);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-27 18:21:37 +00:00
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2011-07-27 18:21:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new WritePixelsView(); )
|