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  联系我,非常感谢。

  • 相关阅读:
    winform 中xml简单的创建和读取
    睡眠和唤醒 进程管理
    [山东省选2011]mindist
    关于zkw流的一些感触
    [noip2011模拟赛]区间问题
    [某ACM比赛]bruteforce
    01、Android进阶Handler原理解析
    02、Java模式UML时序图
    04、Java模式 单例模式
    14、Flutter混合开发
  • 原文地址:https://www.cnblogs.com/wang2650/p/2238461.html
Copyright © 2011-2022 走看看