diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-20 16:33:41 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-20 16:33:41 +0000 |
commit | 4b0757b7489ee5d6bd7149bbcdb0b2af6b7a21cb (patch) | |
tree | d408b82779c2362f9888888456e0441995648fce /tools/skhello.cpp | |
parent | 845220b8179a73c8ec3e53b6dcc11ee3d30ad6a4 (diff) |
add encodeData() to SkImageEncoder, and add encoding to SkImage
BUG=
R=scroggo@google.com
Review URL: https://codereview.chromium.org/15002004
git-svn-id: http://skia.googlecode.com/svn/trunk@9193 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/skhello.cpp')
-rw-r--r-- | tools/skhello.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/tools/skhello.cpp b/tools/skhello.cpp index a4451ac91a..3b8ddee9a6 100644 --- a/tools/skhello.cpp +++ b/tools/skhello.cpp @@ -7,8 +7,11 @@ #include "SkCanvas.h" #include "SkCommandLineFlags.h" +#include "SkData.h" #include "SkGraphics.h" -#include "SkImageEncoder.h" +#include "SkSurface.h" +#include "SkImage.h" +#include "SkStream.h" #include "SkString.h" DEFINE_string2(outFile, o, "skhello.png", "The filename to write the image."); @@ -33,29 +36,29 @@ int tool_main(int argc, char** argv) { SkPaint paint; paint.setAntiAlias(true); paint.setTextSize(SkIntToScalar(30)); + paint.setTextAlign(SkPaint::kCenter_Align); + SkScalar width = paint.measureText(text.c_str(), text.size()); SkScalar spacing = paint.getFontSpacing(); int w = SkScalarRound(width) + 30; int h = SkScalarRound(spacing) + 30; - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); - bitmap.allocPixels(); - SkCanvas canvas(bitmap); - canvas.drawColor(SK_ColorWHITE); + SkImage::Info info = { + w, h, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType + }; + SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); + SkCanvas* canvas = surface->getCanvas(); - paint.setTextAlign(SkPaint::kCenter_Align); - canvas.drawText(text.c_str(), text.size(), - SkIntToScalar(w)/2, SkIntToScalar(h)*2/3, - paint); + canvas->drawColor(SK_ColorWHITE); + canvas->drawText(text.c_str(), text.size(), + SkIntToScalar(w)/2, SkIntToScalar(h)*2/3, + paint); - bool success = SkImageEncoder::EncodeFile(path.c_str(), bitmap, - SkImageEncoder::kPNG_Type, 100); - if (!success) { - SkDebugf("--- failed to write %s\n", path.c_str()); - } - return !success; + SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); + SkAutoDataUnref data(image->encode()); + SkFILEWStream stream(path.c_str()); + return stream.write(data->data(), data->size()); } #if !defined SK_BUILD_FOR_IOS |