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

Unified Diff: tools/skhello.cpp

Issue 15002004: add encodeData() to SkImageEncoder, and add encoding to SkImage (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/images/SkImageEncoder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skhello.cpp
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index a4451ac91a6cad626695e7637f6e01714fcb29e8..3b8ddee9a6202c5c1a06c19387f2df9fc97bb468 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
« no previous file with comments | « src/images/SkImageEncoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698