Chromium Code Reviews| Index: samplecode/SampleImage.cpp |
| diff --git a/samplecode/SampleImage.cpp b/samplecode/SampleImage.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea3cdc43f61f14ea7a018567567ae2e42e635c92 |
| --- /dev/null |
| +++ b/samplecode/SampleImage.cpp |
| @@ -0,0 +1,71 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| + #include "SampleCode.h" |
| + #include "SkPaint.h" |
| + #include "SkCanvas.h" |
| + #include "SkStream.h" |
| + #include "SkImageDecoder.h" |
| + #include "Resources.h" |
| + |
| + class ImageView : public SampleView { |
| + public: |
| + ImageView(const char imageFilename[]) { |
|
scroggo
2015/05/18 14:03:59
nit: Skia uses a four space indent.
Not sure if y
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
|
| + SkString resourcePath = GetResourcePath(imageFilename); |
|
scroggo
2015/05/18 14:03:59
It threw me off for a second that this is lined up
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
|
| + SkImageDecoder* codec = NULL; |
| + SkFILEStream stream(resourcePath.c_str()); |
| + if (stream.isValid()) { |
| + codec = SkImageDecoder::Factory(&stream); |
| + } |
| + if (codec) { |
| + stream.rewind(); |
| + codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); |
| + SkDELETE(codec); |
| + } else { |
|
scroggo
2015/05/18 14:03:59
This should line up with the if statement.
emmaleeroach
2015/05/18 20:04:28
Acknowledged.
|
| + fBM.allocN32Pixels(1, 1); |
| + *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
|
scroggo
2015/05/18 14:03:59
This is just an example, so it doesn't matter too
emmaleeroach
2015/05/18 20:04:28
On 2015/05/18 14:03:59, scroggo wrote:
> This is j
scroggo
2015/05/18 20:43:18
Yes :)
|
| + } |
| + } |
| + |
| + protected: |
| + SkBitmap fBM; |
|
scroggo
2015/05/18 14:03:59
Generally, this should be private unless you want
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> Generally
|
| + |
| + virtual bool onQuery(SkEvent* evt) { |
|
scroggo
2015/05/18 14:03:59
The spacing is wrong for much of this file. Genera
emmaleeroach
2015/05/18 20:04:28
On 2015/05/18 14:03:59, scroggo wrote:
> The spaci
|
| + if (SampleCode::TitleQ(*evt)) { |
| + SampleCode::TitleR(evt, "ImageView"); |
| + return true; |
| + } |
| + return this->INHERITED::onQuery(evt); |
| + } |
| + |
| + virtual void onDrawContent(SkCanvas* canvas) { |
| + |
| + canvas->drawColor(SK_ColorWHITE); |
| + |
| + SkPaint paint; |
| + |
| + paint.setAntiAlias(true); |
| + paint.setTextSize(48); |
| + paint.setFilterQuality(kHigh_SkFilterQuality); |
| + canvas->save(); |
| + canvas->drawBitmap( fBM, 50, 50, &paint ); |
| + canvas->restore(); |
| + |
| + paint.setColor(SK_ColorRED); |
| + paint.setAntiAlias(true); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeWidth(10); |
| + canvas->drawLine(20, 20, 100, 100, paint); |
| + } |
| + |
| + private: |
| + typedef SampleView INHERITED; |
| + |
| + }; |
| + |
| +static SkView* MyFactory() { return new ImageView("yellow_rose.png"); } |
| +static SkViewRegister reg(MyFactory); |