1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/runtime/browser/image_util.h"
9 #include "base/file_util.h"
10 #include "base/strings/string_util.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/size.h"
15 #include "ui/gfx/icon_util.h"
18 namespace xwalk_utils {
20 gfx::Image LoadImageFromFilePath(const base::FilePath& filename) {
21 const base::FilePath::StringType kPNGFormat(FILE_PATH_LITERAL(".png"));
22 const base::FilePath::StringType kICOFormat(FILE_PATH_LITERAL(".ico"));
24 if (EndsWith(filename.value(), kPNGFormat, false)) {
26 base::ReadFileToString(filename, &contents);
27 return gfx::Image::CreateFrom1xPNGBytes(
28 reinterpret_cast<const unsigned char*>(contents.data()),
32 if (EndsWith(filename.value(), kICOFormat, false)) {
34 HICON icon = static_cast<HICON>(LoadImage(NULL,
35 filename.value().c_str(),
39 LR_LOADTRANSPARENT | LR_LOADFROMFILE));
44 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
46 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(*bitmap);
47 image = gfx::Image(image_skia);
52 #elif defined(USE_AURA) && defined(OS_LINUX)
61 LOG(INFO) << "Only support png and ico file format.";
65 } // namespace xwalk_utils