Merge pull request #2453 from etiktin/nativeimage_ico_support_windows
Add support for using .ico icon files on Windows
This commit is contained in:
commit
ec18c2f354
2 changed files with 40 additions and 5 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
#include "base/base64.h"
|
#include "base/base64.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
@ -23,7 +24,11 @@
|
||||||
#include "ui/gfx/image/image_skia.h"
|
#include "ui/gfx/image/image_skia.h"
|
||||||
#include "ui/gfx/image/image_util.h"
|
#include "ui/gfx/image/image_util.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#if defined(OS_WIN)
|
||||||
|
#include "atom/common/asar/archive.h"
|
||||||
|
#include "base/win/scoped_gdi_object.h"
|
||||||
|
#include "ui/gfx/icon_util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -218,11 +223,39 @@ mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
|
||||||
mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
mate::Handle<NativeImage> NativeImage::CreateFromPath(
|
||||||
v8::Isolate* isolate, const base::FilePath& path) {
|
v8::Isolate* isolate, const base::FilePath& path) {
|
||||||
gfx::ImageSkia image_skia;
|
gfx::ImageSkia image_skia;
|
||||||
PopulateImageSkiaRepsFromPath(&image_skia, path);
|
base::FilePath image_path(path);
|
||||||
|
if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// If file is in asar archive, we extract it to a temp file so LoadImage can
|
||||||
|
// load it.
|
||||||
|
base::FilePath asar_path, relative_path;
|
||||||
|
if (asar::GetAsarArchivePath(image_path, &asar_path, &relative_path)) {
|
||||||
|
std::shared_ptr<asar::Archive> archive =
|
||||||
|
asar::GetOrCreateAsarArchive(asar_path);
|
||||||
|
if (archive) {
|
||||||
|
archive->CopyFileOut(relative_path, &image_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the icon from file.
|
||||||
|
base::win::ScopedHICON icon(
|
||||||
|
static_cast<HICON>(
|
||||||
|
LoadImage(NULL, image_path.value().c_str(), IMAGE_ICON, 0, 0,
|
||||||
|
LR_DEFAULTSIZE | LR_LOADFROMFILE)));
|
||||||
|
|
||||||
|
if (icon) {
|
||||||
|
// Convert the icon from the Windows specific HICON to gfx::ImageSkia.
|
||||||
|
scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
|
||||||
|
image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
PopulateImageSkiaRepsFromPath(&image_skia, image_path);
|
||||||
|
}
|
||||||
gfx::Image image(image_skia);
|
gfx::Image image(image_skia);
|
||||||
mate::Handle<NativeImage> handle = Create(isolate, image);
|
mate::Handle<NativeImage> handle = Create(isolate, image);
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
if (IsTemplateFilename(path))
|
if (IsTemplateFilename(image_path))
|
||||||
handle->SetTemplateImage(true);
|
handle->SetTemplateImage(true);
|
||||||
#endif
|
#endif
|
||||||
return handle;
|
return handle;
|
||||||
|
|
|
@ -21,8 +21,10 @@ var appIcon = new Tray(image);
|
||||||
|
|
||||||
## Supported formats
|
## Supported formats
|
||||||
|
|
||||||
Currently `PNG` and `JPEG` are supported. It is recommended to use `PNG`
|
Currently `PNG` and `JPEG` are supported. It is recommended to use `PNG` because
|
||||||
because of its support for transparency and lossless compression.
|
of its support for transparency and lossless compression.
|
||||||
|
|
||||||
|
On Windows, you can also load `ICO` icon from a file path.
|
||||||
|
|
||||||
## High resolution image
|
## High resolution image
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue