zoukankan      html  css  js  c++  java
  • JPG,PNG等格式的图片转换的ICON保存为ICO文件

      Bitmap myBitmap = new Bitmap(Image.FromFile(filePath ), 32, 32);
                IntPtr Hicon = myBitmap.GetHicon();
                Icon newIcon = Icon.FromHandle(Hicon);
                FileStream outStream = new FileStream(@"d:/a.ico", FileMode.OpenOrCreate);
                newIcon.Save(outStream);
                outStream.Flush();

                outStream.Close();

    http://www.cnblogs.com/slave2/archive/2008/09/04/1284759.html

    public System.Drawing.Bitmap GetBitmap(BitmapSource image) { System.Windows.Media.Imaging.BitmapSource bitmapSource = image as BitmapSource; double newWidthRatio = image.Width / (double)bitmapSource.PixelWidth; double newHeightRatio = ((image.Width * bitmapSource.PixelHeight) / (double)bitmapSource.PixelWidth) / (double)bitmapSource.PixelHeight; System.Windows.Media.Imaging.BitmapSource transformedBitmapSource = new System.Windows.Media.Imaging.TransformedBitmap( bitmapSource, new System.Windows.Media.ScaleTransform(newWidthRatio, newHeightRatio)); int width = transformedBitmapSource.PixelWidth; int height = transformedBitmapSource.PixelHeight; int stride = width * ((transformedBitmapSource.Format.BitsPerPixel + 7) / 8); byte[] bits = new byte[height * stride]; transformedBitmapSource.CopyPixels(bits, stride, 0); unsafe { fixed (byte* pBits = bits) { IntPtr ptr = new IntPtr(pBits); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, ptr); return bitmap; } } }
     


    作者:过错
    出处:http://www.cnblogs.com/wang2650/
    关于作者:net开发做的久而已。十余年时光虚度!
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com  联系我,非常感谢。

  • 相关阅读:
    初级Linux学习指南
    2016/09/29 SQL中的join
    2016/09/27 Hadoop Yarn
    2016/06/27 HDFS概述
    2016/09/26 电能和电功率
    【转】2016/09/22 MapReduce初级案例
    2016/09/22 mapreduce
    2016/09/21 java关键字static
    2016/09/21 Java关键字final
    2016/09/21 java split用法
  • 原文地址:https://www.cnblogs.com/wang2650/p/2238461.html
Copyright © 2011-2022 走看看