aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SampleApp.cpp
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2008-12-23 16:49:54 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2008-12-23 16:49:54 +0000
commit0ae6b245f2b79bc04f0801b08fcf05abcf98fd6c (patch)
tree5ce2847123f7abeaf7a0f4a560b2051d5dfc6315 /samplecode/SampleApp.cpp
parent0767e4742e3f8b7c87326abc5129da1e200f8ea1 (diff)
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
Diffstat (limited to 'samplecode/SampleApp.cpp')
-rw-r--r--samplecode/SampleApp.cpp38
1 files changed, 34 insertions, 4 deletions
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);