Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1022)

Unified Diff: samplecode/SampleImage.cpp

Issue 1134113006: dm changes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: changes after code review Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dm/DMSrcSink.cpp ('K') | « gyp/example.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleImage.cpp
diff --git a/samplecode/SampleImage.cpp b/samplecode/SampleImage.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..15781c53c5f39e5122ec3e0988899378e3cd81a1
--- /dev/null
+++ b/samplecode/SampleImage.cpp
@@ -0,0 +1,66 @@
+/*
+ * 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[]) {
+ SkString resourcePath = GetResourcePath(imageFilename);
+ 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 {
+ fBM.allocN32Pixels(1, 1);
+ *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
+ }
+ }
+
+protected:
+ virtual bool onQuery(SkEvent* evt) {
+ 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:
+ SkBitmap fBM;
+ typedef SampleView INHERITED;
+
+ };
+
+static SkView* MyFactory() { return new ImageView("yellow_rose.png"); }
+static SkViewRegister reg(MyFactory);
« dm/DMSrcSink.cpp ('K') | « gyp/example.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698