Skip to content

Instantly share code, notes, and snippets.

View 0x10Ayoub's full-sized avatar

ayoub khourbach 0x10Ayoub

View GitHub Profile
@0x10Ayoub
0x10Ayoub / gist:86f47cf9ab94c50eb756fd71e247bc0c
Created July 16, 2017 21:21 — forked from darkfall/gist:1656050
A simple class that converts a image to a icon in c# without losing image color data, unlike System.Drawing.Icon; ico with png data requires Windows Vista or above
class PngIconConverter
{
/* input image with width = height is suggested to get the best result */
/* png support in icon was introduced in Windows Vista */
public static bool Convert(System.IO.Stream input_stream, System.IO.Stream output_stream, int size, bool keep_aspect_ratio = false)
{
System.Drawing.Bitmap input_bit = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(input_stream);
if (input_bit != null)
{
int width, height;