From 0ae6b245f2b79bc04f0801b08fcf05abcf98fd6c Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Tue, 23 Dec 2008 16:49:54 +0000 Subject: add mac image-encoding add 'f' to sampleapp, which writes a png file for the currnet screen git-svn-id: http://skia.googlecode.com/svn/trunk@47 2bbb7eff-a529-9590-31e7-b0007b416f81 --- samplecode/SampleApp.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'samplecode/SampleApp.cpp') diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 365f558345..df0723f3e1 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -2,6 +2,7 @@ #include "SkDevice.h" #include "SkGLCanvas.h" #include "SkGraphics.h" +#include "SkImageDecoder.h" #include "SkPaint.h" #include "SkPicture.h" #include "SkStream.h" @@ -380,6 +381,17 @@ bool SampleWindow::onEvent(const SkEvent& evt) { return this->INHERITED::onEvent(evt); } +static void cleanup_for_filename(SkString* name) { + char* str = name->writable_str(); + for (int i = 0; i < name->size(); i++) { + switch (str[i]) { + case ':': str[i] = '-'; break; + case '/': str[i] = '-'; break; + case ' ': str[i] = '_'; break; + default: break; + } + } +} bool SampleWindow::onHandleChar(SkUnichar uni) { int dx = 0xFF; @@ -411,10 +423,28 @@ bool SampleWindow::onHandleChar(SkUnichar uni) { return true; } - if ('a' == uni) { - fAnimating = !fAnimating; - this->postAnimatingEvent(); - this->updateTitle(); + switch (uni) { + case 'a': + fAnimating = !fAnimating; + this->postAnimatingEvent(); + this->updateTitle(); + return true; + case 'f': { + const char* title = this->getTitle(); + if (title[0] == 0) { + title = "sampleapp"; + } + SkString name(title); + cleanup_for_filename(&name); + name.append(".png"); + if (SkImageEncoder::EncodeFile(name.c_str(), this->getBitmap(), + SkImageEncoder::kPNG_Type)) { + SkDebugf("Created %s\n", name.c_str()); + } + return true; + } + default: + break; } return this->INHERITED::onHandleChar(uni); -- cgit v1.2.3