diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-03 13:39:57 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-03 13:39:57 +0000 |
commit | b196374e6f5b66ba911a2be6ddb31c6692a3615a (patch) | |
tree | e85ce8c29dc9367b03f243e2c6c111525771287e /samplecode | |
parent | c9af5d8d8a00875905349bf43e6920c14d77e75f (diff) |
--picture foo now works if foo is an image (.png, .jpeg) or a picture (.skp)
git-svn-id: http://skia.googlecode.com/svn/trunk@4944 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SamplePictFile.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp index f81a02ad23..b24f908136 100644 --- a/samplecode/SamplePictFile.cpp +++ b/samplecode/SamplePictFile.cpp @@ -31,6 +31,26 @@ class PictFileView : public SampleView { SkString fFilename; SkPicture* fPicture; + + static SkPicture* LoadPicture(const char path[]) { + SkPicture* pic = NULL; + + SkBitmap bm; + if (SkImageDecoder::DecodeFile(path, &bm)) { + bm.setImmutable(); + pic = SkNEW(SkPicture); + SkCanvas* can = pic->beginRecording(bm.width(), bm.height()); + can->drawBitmap(bm, 0, 0, NULL); + pic->endRecording(); + } else { + SkFILEStream stream(path); + if (stream.isValid()) { + pic = SkNEW_ARGS(SkPicture, (&stream)); + } + } + return pic; + } + public: PictFileView(const char name[] = NULL) : fFilename(name) { fPicture = NULL; @@ -53,14 +73,15 @@ protected: } virtual void onDrawContent(SkCanvas* canvas) { - if (NULL == fPicture) { - SkFILEStream stream(fFilename.c_str()); - fPicture = SkNEW_ARGS(SkPicture, (&stream)); + if (!fPicture) { + fPicture = LoadPicture(fFilename.c_str()); + } + if (fPicture) { + canvas->drawPicture(*fPicture); } - canvas->drawPicture(*fPicture); } -private: +private: typedef SampleView INHERITED; }; |