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

Side by Side 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 unified diff | Download patch
« dm/DMSrcSink.cpp ('K') | « gyp/example.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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
8 #include "SampleCode.h"
9 #include "SkPaint.h"
10 #include "SkCanvas.h"
11 #include "SkStream.h"
12 #include "SkImageDecoder.h"
13 #include "Resources.h"
14
15 class ImageView : public SampleView {
16 public:
17 ImageView(const char imageFilename[]) {
18 SkString resourcePath = GetResourcePath(imageFilename);
19 SkImageDecoder* codec = NULL;
20 SkFILEStream stream(resourcePath.c_str());
21 if (stream.isValid()) {
22 codec = SkImageDecoder::Factory(&stream);
23 }
24 if (codec) {
25 stream.rewind();
26 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDeco dePixels_Mode);
27 SkDELETE(codec);
28 } else {
29 fBM.allocN32Pixels(1, 1);
30 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
31 }
32 }
33
34 protected:
35 virtual bool onQuery(SkEvent* evt) {
36 if (SampleCode::TitleQ(*evt)) {
37 SampleCode::TitleR(evt, "ImageView");
38 return true;
39 }
40 return this->INHERITED::onQuery(evt);
41 }
42
43 virtual void onDrawContent(SkCanvas* canvas) {
44 canvas->drawColor(SK_ColorWHITE);
45 SkPaint paint;
46 paint.setAntiAlias(true);
47 paint.setTextSize(48);
48 paint.setFilterQuality(kHigh_SkFilterQuality);
49 canvas->save();
50 canvas->drawBitmap( fBM, 50, 50, &paint );
51 canvas->restore();
52 paint.setColor(SK_ColorRED);
53 paint.setAntiAlias(true);
54 paint.setStyle(SkPaint::kStroke_Style);
55 paint.setStrokeWidth(10);
56 canvas->drawLine(20, 20, 100, 100, paint);
57 }
58
59 private:
60 SkBitmap fBM;
61 typedef SampleView INHERITED;
62
63 };
64
65 static SkView* MyFactory() { return new ImageView("yellow_rose.png"); }
66 static SkViewRegister reg(MyFactory);
OLDNEW
« 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