Using .png files instead of using .ico files in Windows programs

Hi, I have a collection of good .png files .... meanwhile, I develop software based on winnings and need some .ico files as icons for toolbar buttons and ...

Can I use a .png file as an icon? or what?

thanks

+3
source share
4 answers

As a workaround, you can use IrfanView to convert your * .png file to a * .ico file (or any other image in ico) and use it.

http://www.irfanview.com/main_download_engl.htm

+8
source

.NET, , afaik PNG . , C/++ GDI/win32?

, , GDI. , , BMP/JPEG BITMAP, ICO/GIF .

, , , GDI +, PNG -? , DLL, , , :

static GpImage *background = NULL;

GDIPLOADIMAGEFROMSTREAM GdipLoadImageFromStream;
GDIPLUSSTARTUP          GdiplusStartup; 
GDIPPLUSSHUTDOWN        GdiplusShutdown;
GDIPCREATEFROMHDC       GdipCreateFromHDC;
GDIPDELETEGRAPHICS      GdipDeleteGraphics;
GDIPDRAWIMAGEI          GdipDrawImageI;
GDIPDRAWIMAGERECTI      GdipDrawImageRectI;
GDIPLUS_STARTUP_INPUT   GdiplusStartupInput; 

void LoadPNG(GpImage **image, int resource, HMODULE hInstance)
{
  HRSRC     resrc;
  LPSTREAM  lpstr;
  HGLOBAL   hPng;
  LPVOID    fByte; 
  GpImage *img  = NULL;

  resrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(resource), TEXT("PNG"));
  hPng  = LoadResource(GetModuleHandle(NULL), resrc);
  fByte = LockResource(hPng);
  lpstr = SHCreateMemStream(fByte, 200000); 
  GdipLoadImageFromStream(lpstr, &img); 
  *image = img;
}

void CreateBack(HWND hWnd)
{
  HDC  memDC = NULL;      
  HDC  hdc   = NULL; 
  RECT rect;

  DeleteObject(curBack);
  GetClientRect(hWnd, &rect);
  hdc = GetDC(hWnd); 

  memDC   = CreateCompatibleDC(hdc); 
  curBack = CreateCompatibleBitmap(hdc, rect.right, 44);   
  SelectObject(memDC, curBack); 

  /* gdiplus - background*/ {
    int e = 0;
    GpGraphics *g;  
    GdipCreateFromHDC(memDC, &g); 
    GdipDrawImageRectI(g, background,  e, 0, 971, 44);
    GdipDeleteGraphics(g);  
  }

  DeleteObject(memDC);  
  ReleaseDC(hWnd, hdc);  
}

: GDI + CPU/ . , gdi BMP.

+1
+1

, , PNG, ICOs. , , PNG ICO, ImageMagick ( ), MSPaint - .

, (, libpng PNG), , , , . , , , , Win32 API.

0

Source: https://habr.com/ru/post/1711466/


All Articles