C#操作CUR的类

三菱PLC(FX5U)与C#通信说明 三菱PLC(FX5U)与C#通信说明 所需软件及插件:Visual Studio 2015,GX Work3,MX Component 一、 三菱软件下载安装 GX Work3:https://pan.baidu.com/s/129VnuvQ8R9GjfY4CnuR7Hw 提取码:5l4e MX Component: https://pan.baidu.com/s/1Tc2eC7vog7a7QQIBLppn6w 提取码:7n0b 三菱官方下载网址: http://cn.mitsubishielec 阅读详情

 Zgke.MyImage.ImageFile.ImageCur _Cur = new Zgke1.MyImage.ImageFile.ImageCur();
            _Cur.CurImage.Add(this.Icon.ToBitmap());
            _Cur.SaveImage(@"C:/1.cur", true);

 

 

 

只支持2种保存方式  24位色 和 32位色 昨天发的忘记放上BIT反转的方法了. 今天更新上.

 

 

 

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;


namespace Zgke.MyImage.ImageFile
{

    /// <summary>
    /// CUR文件操作类
    /// zgke@sina.com
    /// qq:116149
    /// </summary>
    public class ImageCur
    {
        private class CurHead
        {
            private byte[] m_Retain = new byte[2];
            private byte[] m_Type = new byte[] { 0x02, 0x00 };
            private byte[] m_ImageCount = new byte[2];
            private byte m_ImageWidth;
            private byte m_ImageHeight;
            private byte m_ColorCount;
            private byte[] m_NotUser = new byte[5];
            private byte[] m_ImageLength = new byte[4];
            private byte[] m_ImageRVA = new byte[4];

            /// <summary>
            /// 图形高
            /// </summary>
            public byte ImageHeight { get { return m_ImageHeight; } set { m_ImageHeight = value; } }
            /// <summary>
            /// 图象个数
            /// </summary>
            public ushort ImageCount { get { return BitConverter.ToUInt16(m_ImageCount, 0); } set { m_ImageCount = BitConverter.GetBytes(value); } }
            /// <summary>
            /// 图形宽
            /// </summary>
            public byte ImageWidth { get { return m_ImageWidth; } set { m_ImageWidth = value; } }
            /// <summary>
            /// 色彩数 (256以下色用)
            /// </summary>         
            public byte ColorCount { get { return m_ColorCount; } set { m_ColorCount = value; } }
            /// <summary>
            /// 图象数据块的长度
            /// </summary>
            public uint ImageLength { get { return BitConverter.ToUInt32(m_ImageLength, 0); } set { m_ImageLength = BitConverter.GetBytes(value); } }
            /// <summary>
            /// 图象数据块相对于文件头部的偏移量
            /// </summary>
            public uint ImageRVA { get { return BitConverter.ToUInt32(m_ImageRVA, 0); } set { m_ImageRVA = BitConverter.GetBytes(value); } }

            public CurHead()
            {

            }

            public CurHead(byte[] p_Data)
            {
                ImageCount = BitConverter.ToUInt16(p_Data, 4);
                ImageHeight = p_Data[7];
                ImageWidth = p_Data[6];
                ColorCount = p_Data[8];

                ImageLength = BitConverter.ToUInt32(p_Data, 14);
                ImageRVA = BitConverter.ToUInt32(p_Data, 18);
            }

            public byte[] GetByte()
            {
                byte[] _ReturnBytes = new byte[22];

                _ReturnBytes[0] = m_Retain[0];
                _ReturnBytes[1] = m_Retain[1];

                _ReturnBytes[2] = m_Retain[0];
                _ReturnBytes[3] = m_Retain[1];
                _ReturnBytes[4] = m_ImageCount[0];
                _ReturnBytes[5] = m_ImageCount[1];


                _ReturnBytes[6] = m_ImageWidth;
                _ReturnBytes[7] = m_ImageHeight;
                _ReturnBytes[8] = m_ColorCount;

                _ReturnBytes[14] = m_ImageLength[0];
                _ReturnBytes[15] = m_ImageLength[1];
                _ReturnBytes[16] = m_ImageLength[2];
                _ReturnBytes[17] = m_ImageLength[3];

                _ReturnBytes[18] = m_ImageRVA[0];
                _ReturnBytes[19] = m_ImageRVA[1];
                _ReturnBytes[20] = m_ImageRVA[2];
                _ReturnBytes[21] = m_ImageRVA[3];
                return _ReturnBytes;
            }

            public byte[] GetImageByte()
            {
                byte[] _ReturnBytes = new byte[16];

                _ReturnBytes[0] = m_ImageWidth;
                _ReturnBytes[1] = m_ImageHeight;
                _ReturnBytes[2] = m_ColorCount;

                _ReturnBytes[8] = m_ImageLength[0];
                _ReturnBytes[9] = m_ImageLength[1];
                _ReturnBytes[10] = m_ImageLength[2];
                _ReturnBytes[11] = m_ImageLength[3];

                _ReturnBytes[12] = m_ImageRVA[0];
                _ReturnBytes[13] = m_ImageRVA[1];
                _ReturnBytes[14] = m_ImageRVA[2];
                _ReturnBytes[15] = m_ImageRVA[3];
                return _ReturnBytes;

            }
        }


        private CurHead m_CurHead;
        private Bitmap m_CurImage;

        private IList<Image> m_CurList = new List<Image>();

        public ImageCur(string p_FileFullName)
        {
            byte[] _FileBytes = File.ReadAllBytes(p_FileFullName);
            ImageCurBytes(_FileBytes);
        }

        public ImageCur(byte[] p_FileBytes)
        {
            ImageCurBytes(p_FileBytes);
        }

        private void ImageCurBytes(byte[] p_Bytes)
        {
            m_CurHead = new CurHead(p_Bytes);

            for (int i = 0; i != m_CurHead.ImageCount; i++)
            {
                m_CurHead.ImageWidth = (byte)BitConverter.ToInt16(p_Bytes, (int)m_CurHead.ImageRVA + 4);
                m_CurHead.ImageHeight = (byte)(BitConverter.ToInt16(p_Bytes, (int)m_CurHead.ImageRVA + 8) / 2);
                short _Piex = BitConverter.ToInt16(p_Bytes, (int)m_CurHead.ImageRVA + 14);
                LoadImgae(_Piex, p_Bytes, (int)m_CurHead.ImageRVA + 40);
                m_CurList.Add((Image)m_CurImage);

                byte[] _Value = new byte[4];
                _Value[3] = p_Bytes[((i + 1) * 16) + 18 + 3];
                _Value[2] = p_Bytes[((i + 1) * 16) + 18 + 2];
                _Value[1] = p_Bytes[((i + 1) * 16) + 18 + 1];
                _Value[0] = p_Bytes[((i + 1) * 16) + 18];

                m_CurHead.ImageRVA = BitConverter.ToUInt32(_Value, 0);
            }
        }

        public ImageCur()
        {
        }

        #region Read
        private void Load32(byte[] p_FileBytes, byte[] p_NewData, int p_ReadIndex, int p_Width, int p_Height, int p_MashIndex, BitmapData p_NewBitmapData)
        {
            int _WriteIndex = 0;

            for (int i = p_NewBitmapData.Height - 1; i != -1; i--)
            {
                _WriteIndex = i * p_NewBitmapData.Stride;
                for (int z = 0; z != p_NewBitmapData.Width; z++)
                {
                    p_NewData[_WriteIndex + (z * 4)] = p_FileBytes[p_ReadIndex];
                    p_NewData[_WriteIndex + (z * 4) + 1] = p_FileBytes[p_ReadIndex + 1];
                    p_NewData[_WriteIndex + (z * 4) + 2] = p_FileBytes[p_ReadIndex + 2];
                    p_NewData[_WriteIndex + (z * 4) + 3] = p_FileBytes[p_ReadIndex + 3];
                    p_ReadIndex += 4;
                }
            }
        }
        private void Load24(byte[] p_FileBytes, byte[] p_NewData, int p_ReadIndex, int p_Width, int p_Height, int p_MashIndex, BitmapData p_NewBitmapData)
        {
            int _WriteIndex = 0;

            int _MashStride = p_Width / 8;
            if (p_Width % 8 != 0) _MashStride++;
            if (_MashStride % 4 != 0) _MashStride += _MashStride % 4;
            byte[] _MashBytes = new byte[_MashStride * p_Height];
            Array.Copy(p_FileBytes, p_MashIndex, _MashBytes, 0, _MashBytes.Length);
            for (int i = 0; i != _MashBytes.Length; i++)
            {
                _MashBytes[i] = ReverseByte(_MashBytes[i]);
            }
            BitArray _MashArray = new BitArray(_MashBytes);

            for (int i = p_NewBitmapData.Height - 1; i != -1; i--)
            {
                p_MashIndex = (p_Height - 1 - i) * (_MashStride * 8);

                _WriteIndex = i * p_NewBitmapData.Stride;
                for (int z = 0; z != p_NewBitmapData.Width; z++)
                {
                    p_NewData[_WriteIndex + (z * 4)] = p_FileBytes[p_ReadIndex];
                    p_NewData[_WriteIndex + (z * 4) + 1] = p_FileBytes[p_ReadIndex + 1];
                    p_NewData[_WriteIndex + (z * 4) + 2] = p_FileBytes[p_ReadIndex + 2];
                    p_NewData[_WriteIndex + (z * 4) + 3] = 0xFF;
                    if (_MashArray[p_MashIndex]) p_NewData[_WriteIndex + (z * 4) + 3] = 0x00; //                               

                    p_ReadIndex += 3;

                    p_MashIndex++;
                }
            }
        }
        private void Load8(byte[] p_FileBytes, byte[] p_NewData, int p_ReadIndex, int p_Width, int p_Height, int p_MashIndex, BitmapData p_NewBitmapData)
        {
            int _WriteIndex = 0;

            Hashtable _ColorHashTable = new Hashtable();
            for (int i = 0; i != 256; i++)
            {
                _ColorHashTable.Add(i.ToString(), Color.FromArgb(p_FileBytes[p_ReadIndex + 3], p_FileBytes[p_ReadIndex + 2], p_FileBytes[p_ReadIndex + 1], p_FileBytes[p_ReadIndex]));
                p_ReadIndex += 4;
            }
            p_MashIndex = p_Width * p_Height + p_ReadIndex;
            int _MashStride = p_Width / 8;
            if (p_Width % 8 != 0) _MashStride++;
            if (_MashStride % 4 != 0) _MashStride += _MashStride % 4;
            byte[] _MashBytes = new byte[_MashStride * p_Height];
            Array.Copy(p_FileBytes, p_MashIndex, _MashBytes, 0, _MashBytes.Length);
            for (int i = 0; i != _MashBytes.Length; i++)
            {
                _MashBytes[i] = ReverseByte(_MashBytes[i]);
            }
            BitArray _MashArray = new BitArray(_MashBytes);


            for (int i = p_NewBitmapData.Height - 1; i != -1; i--)
            {
                p_MashIndex = (p_Height - 1 - i) * (_MashStride * 8);

                _WriteIndex = i * p_NewBitmapData.Stride;
                for (int z = 0; z != p_NewBitmapData.Width; z++)
                {
                    byte _Index = p_FileBytes[p_ReadIndex];
                    Color _SetColor = (Color)_ColorHashTable[_Index.ToString()];

                    p_NewData[_WriteIndex + (z * 4)] = (byte)_SetColor.B;
                    p_NewData[_WriteIndex + (z * 4) + 1] = (byte)_SetColor.G;
                    p_NewData[_WriteIndex + (z * 4) + 2] = (byte)_SetColor.R;
                    p_NewData[_WriteIndex + (z * 4) + 3] = 0xFF;
                    if (_MashArray[p_MashIndex]) p_NewData[_WriteIndex + (z * 4) + 3] = 0x00; // 
                    p_ReadIndex++;
                    p_MashIndex++;
                }
            }
        }
        private void Load4(byte[] p_FileBytes, byte[] p_NewData, int p_ReadIndex, int p_Width, int p_Height, int p_MashIndex, BitmapData p_NewBitmapData)
        {
            int _WriteIndex = 0;

            Hashtable _ColorHashTable = new Hashtable();
            for (int i = 0; i != 16; i++)
            {
                _ColorHashTable.Add(i.ToString(), Color.FromArgb(p_FileBytes[p_ReadIndex + 3], p_FileBytes[p_ReadIndex + 2], p_FileBytes[p_ReadIndex + 1], p_FileBytes[p_ReadIndex]));
                p_ReadIndex += 4;
            }
            p_MashIndex = (p_Width * p_Height / 2) + p_ReadIndex;
            int _MashStride = p_Width / 8;
            if (p_Width % 8 != 0) _MashStride++;
            if (_MashStride % 4 != 0) _MashStride += _MashStride % 4;
            byte[] _MashBytes = new byte[_MashStride * p_Height];
            Array.Copy(p_FileBytes, p_MashIndex, _MashBytes, 0, _MashBytes.Length);
            for (int i = 0; i != _MashBytes.Length; i++)
            {
                _MashBytes[i] = ReverseByte(_MashBytes[i]);
            }
            BitArray _MashArray = new BitArray(_MashBytes);

            bool _Lith = true;
            for (int i = p_NewBitmapData.Height - 1; i != -1; i--)
            {
                p_MashIndex = (p_Height - 1 - i) * (_MashStride * 8);

                _WriteIndex = i * p_NewBitmapData.Stride;
                for (int z = 0; z != p_NewBitmapData.Width; z++)
                {
                    byte _Index = p_FileBytes[p_ReadIndex];

                    if (_Lith)
                    {
                        _Index = (byte)((_Index & 0xF0) >> 4);
                        _Lith = false;
                    }
                    else
                    {
                        _Index = (byte)(_Index & 0x0F);  //后面的F 
                        _Lith = true;
                        p_ReadIndex++;
                    }
                    Color _SetColor = (Color)_ColorHashTable[_Index.ToString()];

                    p_NewData[_WriteIndex + (z * 4)] = (byte)_SetColor.B;
                    p_NewData[_WriteIndex + (z * 4) + 1] = (byte)_SetColor.G;
                    p_NewData[_WriteIndex + (z * 4) + 2] = (byte)_SetColor.R;
                    p_NewData[_WriteIndex + (z * 4) + 3] = 0xFF;

                    if (_MashArray[p_MashIndex]) p_NewData[_WriteIndex + (z * 4) + 3] = 0x00; // 


                    p_MashIndex++;
                }
            }
        }
        private void Load1(byte[] p_FileBytes, byte[] p_NewData, int p_ReadIndex, int p_Width, int p_Height, int p_MashIndex, BitmapData p_NewBitmapData)
        {
            int _WriteIndex = 0;

            Hashtable _ColorHashTable = new Hashtable();
            for (int i = 0; i != 2; i++)
            {
                _ColorHashTable.Add(i.ToString(), Color.FromArgb(p_FileBytes[p_ReadIndex + 3], p_FileBytes[p_ReadIndex + 2], p_FileBytes[p_ReadIndex + 1], p_FileBytes[p_ReadIndex]));
                p_ReadIndex += 4;
            }
            p_MashIndex = (p_Width * p_Height / 8) + p_ReadIndex;
            int _MashStride = p_Width / 8;
            if (p_Width % 8 != 0) _MashStride++;
            if (_MashStride % 4 != 0) _MashStride += _MashStride % 4;
            byte[] _MashBytes = new byte[_MashStride * p_Height];
            Array.Copy(p_FileBytes, p_MashIndex, _MashBytes, 0, _MashBytes.Length);
            for (int i = 0; i != _MashBytes.Length; i++)
            {
                _MashBytes[i] = ReverseByte(_MashBytes[i]);
            }
            BitArray _MashArray = new BitArray(_MashBytes);

            int _Lith = 7;
            for (int i = p_NewBitmapData.Height - 1; i != -1; i--)
            {
                p_MashIndex = (p_Height - 1 - i) * (_MashStride * 8);

                _WriteIndex = i * p_NewBitmapData.Stride;
                for (int z = 0; z != p_NewBitmapData.Width; z++)
                {
                    byte _Index = p_FileBytes[p_ReadIndex];


                    BitArray _ColorIndex = new BitArray(new byte[] { _Index });
                    if (_ColorIndex[_Lith])
                    {
                        _Index = 1;
                    }
                    else
                    {
                        _Index = 0;
                    }
                    if (_Lith == 0)
                    {
                        p_ReadIndex++;
                        _Lith = 7;
                    }
                    else
                    {
                        _Lith--;
                    }

                    Color _SetColor = (Color)_ColorHashTable[_Index.ToString()];

                    p_NewData[_WriteIndex + (z * 4)] = (byte)_SetColor.B;
                    p_NewData[_WriteIndex + (z * 4) + 1] = (byte)_SetColor.G;
                    p_NewData[_WriteIndex + (z * 4) + 2] = (byte)_SetColor.R;
                    p_NewData[_WriteIndex + (z * 4) + 3] = 0xFF;

                    if (_MashArray[p_MashIndex]) p_NewData[_WriteIndex + (z * 4) + 3] = 0x00; //    

                    p_MashIndex++;
                }
            }

        }
        #endregion

        private void LoadImgae(short m_Piex, byte[] p_FileBytes, int _StarIndex)
        {
            int _Width = m_CurHead.ImageWidth;
            int _Height = m_CurHead.ImageHeight;
            m_CurImage = new Bitmap(_Width, _Height, PixelFormat.Format32bppArgb);
            BitmapData _NewBitmapData = m_CurImage.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            byte[] _NewData = new byte[_NewBitmapData.Stride * _NewBitmapData.Height];

            int _ReadIndex = _StarIndex;
            int _MashIndex = 0;

            switch (m_Piex)
            {
                case 1:
                    _MashIndex = (_Width * _Height / 8) + _ReadIndex;
                    Load1(p_FileBytes, _NewData, _ReadIndex, _Width, _Height, _MashIndex, _NewBitmapData);
                    break;
                case 4:
                    _MashIndex = (_Width * _Height / 2) + _ReadIndex;
                    Load4(p_FileBytes, _NewData, _ReadIndex, _Width, _Height, _MashIndex, _NewBitmapData);
                    break;
                case 8:
                    _MashIndex = _Width * _Height + _ReadIndex;
                    Load8(p_FileBytes, _NewData, _ReadIndex, _Width, _Height, _MashIndex, _NewBitmapData);
                    break;
                case 24:
                    _MashIndex = _Width * _Height * 3 + _ReadIndex;
                    Load24(p_FileBytes, _NewData, _ReadIndex, _Width, _Height, _MashIndex, _NewBitmapData);
                    break;
                case 32:
                    _MashIndex = _Width * _Height * 4 + _ReadIndex;
                    Load32(p_FileBytes, _NewData, _ReadIndex, _Width, _Height, _MashIndex, _NewBitmapData);
                    break;
                default:
                    throw new Exception("不支持的格式");
            }
            Marshal.Copy(_NewData, 0, _NewBitmapData.Scan0, _NewData.Length);
            m_CurImage.UnlockBits(_NewBitmapData);
        }

        public void SaveImage(string p_FileName, bool Argb24)
        {
            if (m_CurList.Count == 0) return;

            FileStream _File = new FileStream(p_FileName, FileMode.Create, FileAccess.Write);
            m_CurHead = new CurHead();
            _File.Write(new byte[] { 0x00, 0x00, 0x02, 0x00 }, 0, 4);
            _File.Write(BitConverter.GetBytes((ushort)m_CurList.Count), 0, 2);

            List<byte[]> _ImageByteList = new List<byte[]>();

            m_CurHead.ImageRVA = (uint)m_CurList.Count * 16 + 6;
            for (int i = 0; i != m_CurList.Count; i++)
            {
                if (m_CurList[i].Width > 255 || m_CurList[i].Height > 255)
                {
                    _File.Close();
                    throw new Exception("图形文件过大!");
                }

                byte[] _ImageSize = new byte[10];
                if (Argb24 == true)
                {
                    _ImageSize = GetImageBytes24(i);
                }
                else
                {
                    _ImageSize = GetImageBytes32(i);
                }

                m_CurHead.ImageHeight = (byte)CurImage[i].Height;
                m_CurHead.ImageWidth = (byte)CurImage[i].Width;
                m_CurHead.ImageRVA += m_CurHead.ImageLength;
                m_CurHead.ImageLength = (uint)_ImageSize.Length;


                _ImageByteList.Add(_ImageSize);
                _File.Write(m_CurHead.GetImageByte(), 0, 16);
            }

            for (int i = 0; i != _ImageByteList.Count; i++)
            {
                byte[] _Height = BitConverter.GetBytes((uint)(m_CurList[i].Height * 2));

                _ImageByteList[i][8] = _Height[0];
                _ImageByteList[i][9] = _Height[1];
                _ImageByteList[i][10] = _Height[2];
                _ImageByteList[i][11] = _Height[3];

                _File.Write(_ImageByteList[i], 0, _ImageByteList[i].Length);
            }

            _File.Close();
        }

        public MemoryStream SaveImage(bool Argb24)
        {
            if (m_CurList.Count == 0) throw new Exception("无图形可保存");

            MemoryStream _Memory = new MemoryStream();
            m_CurHead = new CurHead();
            _Memory.Write(new byte[] { 0x00, 0x00, 0x02, 0x00 }, 0, 4);
            _Memory.Write(BitConverter.GetBytes((ushort)m_CurList.Count), 0, 2);

            List<byte[]> _ImageByteList = new List<byte[]>();

            m_CurHead.ImageRVA = (uint)m_CurList.Count * 16 + 6;
            for (int i = 0; i != m_CurList.Count; i++)
            {
                if (m_CurList[i].Width > 255 || m_CurList[i].Height > 255)
                {
                    _Memory.Close();
                    throw new Exception("图形文件过大!");
                }

                byte[] _ImageSize = new byte[10];
                if (Argb24 == true)
                {
                    _ImageSize = GetImageBytes24(i);
                }
                else
                {
                    _ImageSize = GetImageBytes32(i);
                }
                m_CurHead.ImageHeight = (byte)CurImage[i].Height;
                m_CurHead.ImageWidth = (byte)CurImage[i].Width;
                m_CurHead.ImageRVA += m_CurHead.ImageLength;
                m_CurHead.ImageLength = (uint)_ImageSize.Length;


                _ImageByteList.Add(_ImageSize);
                _Memory.Write(m_CurHead.GetImageByte(), 0, 16);
            }

            for (int i = 0; i != _ImageByteList.Count; i++)
            {
                byte[] _Height = BitConverter.GetBytes((uint)(m_CurList[i].Height * 2));

                _ImageByteList[i][8] = _Height[0];
                _ImageByteList[i][9] = _Height[1];
                _ImageByteList[i][10] = _Height[2];
                _ImageByteList[i][11] = _Height[3];

                _Memory.Write(_ImageByteList[i], 0, _ImageByteList[i].Length);
            }

            return _Memory;
        }

        /// <summary>
        /// CUR图形
        /// </summary>
        public IList<Image> CurImage { get { return m_CurList; } set { m_CurList = value; } }

     

 

       #region 保存
        private byte[] GetImageBytes24(int p_ImageIndex)
        {
            int _Width = m_CurList[p_ImageIndex].Width;
            int _Height = m_CurList[p_ImageIndex].Height;
    
            Bitmap _Image = new Bitmap(_Width, _Height, PixelFormat.Format32bppArgb);
            Graphics _Graphcis = Graphics.FromImage(_Image);
            _Graphcis.DrawImage(m_CurList[p_ImageIndex], 0, 0, 32, 32);
            _Graphcis.Dispose();
            BitmapData _Data = _Image.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] _NewByteImage = new byte[_Width * _Height * 3];
            byte[] _OldByteImage = new byte[_Width * _Height * 4];

            Marshal.Copy(_Data.Scan0, _OldByteImage, 0, _OldByteImage.Length);
            _Image.UnlockBits(_Data);

            int _MashStride = _Image.Width / 8;
            if (_MashStride % 4 != 0) _MashStride += _MashStride % 4;
            byte[] _MashBytes = new byte[_MashStride * _Height];

            int _OldIndex = 0;
            int _NewIndex = 0;

            int _MashIndex = 0;
            int _Mash = 0;

            int _WriteHeight = 0;
            for (int i = _Height-1; i != -1; i--)
            {
                _Mash = _WriteHeight * _MashStride;
                _NewIndex = _WriteHeight * _Width * 3;
                _OldIndex = i * _Data.Stride;
                for (int z = 0; z != _Width; z++)
                {
                    _NewByteImage[_NewIndex] = _OldByteImage[_OldIndex];
                    _NewByteImage[_NewIndex + 1] = _OldByteImage[_OldIndex + 1];
                    _NewByteImage[_NewIndex + 2] = _OldByteImage[_OldIndex + 2];

                    if (_OldByteImage[_OldIndex + 3] == 255)
                    {
                        _MashBytes[_Mash] = (byte)(_MashBytes[_Mash] << 1 & 0xFE);
                    }
                    else
                    {
                        _MashBytes[_Mash] = (byte)(_MashBytes[_Mash] << 1 | 0x1);
                     
                    }
                    _OldIndex += 4;
                    _NewIndex += 3;                   
                   
                    _MashIndex++;
                    if (_MashIndex % 8 == 0)
                    {
                        _Mash++;
                        _MashIndex = 0;
                    }
                }
                _WriteHeight++;
            }
            MemoryStream _Memory = new MemoryStream();  
            Bitmap _NewBitmap = new Bitmap(10, 1, PixelFormat.Format24bppRgb);         
            _NewBitmap.Save(_Memory, ImageFormat.Bmp);
            _Memory.Position = 0x0e;
            byte[] _BytesHead = new byte[40];
            _Memory.Read(_BytesHead, 0, 40);
            _Memory.Dispose();
                  
            MemoryStream _Return = new MemoryStream();  

            byte[] _WidthBytes = BitConverter.GetBytes(_Width);
            byte[] _HeightBytes = BitConverter.GetBytes(_Height*2);

            _BytesHead[4] = _WidthBytes[0];
            _BytesHead[5] = _WidthBytes[1];
            _BytesHead[6] = _WidthBytes[2];
            _BytesHead[7] = _WidthBytes[3];

            _BytesHead[8] = _HeightBytes[0];
            _BytesHead[9] = _HeightBytes[1];
            _BytesHead[10] = _HeightBytes[2];
            _BytesHead[11] = _HeightBytes[3];

            _Return.Write(_BytesHead, 0, 40);

            _Return.Write(_NewByteImage, 0, _NewByteImage.Length);
            _Return.Write(_MashBytes, 0, _MashBytes.Length);

            return _Return.ToArray();
        }

        private byte[] GetImageBytes32(int p_ImageIndex)
        {
            MemoryStream _Memory = new MemoryStream();
            if (m_CurList[p_ImageIndex].PixelFormat != PixelFormat.Format32bppArgb)
            {
                Bitmap _Image = new Bitmap(m_CurList[p_ImageIndex].Width, m_CurList[p_ImageIndex].Height, PixelFormat.Format32bppArgb);
                Graphics _Graphcis = Graphics.FromImage(_Image);
                _Graphcis.RotateTransform(90);
                _Graphcis.Dispose();
                _Image.Save(_Memory, ImageFormat.Bmp);
            }
            else
            {
                m_CurList[p_ImageIndex].Save(_Memory, ImageFormat.Bmp);
            }
            byte[] _Test = _Memory.ToArray();
            byte[] _ImageBytes = new byte[_Memory.Length - 0x0E];
            _Memory.Position = 0x0E;
            _Memory.Read(_ImageBytes, 0, _ImageBytes.Length);

            return _ImageBytes;
        }
        #endregion

 

 

 


        /// <summary>
        /// 反转byte
        /// </summary>
        /// <param name="p_Bytes"></param>
        /// <returns></returns>
        public static byte ReverseByte(byte p_Byte)
        {
            byte _ReverseBytes = 0;
            _ReverseBytes |= (byte)(((p_Byte >> 0) & 0x01) << 7);
            _ReverseBytes |= (byte)(((p_Byte >> 1) & 0x01) << 6);
            _ReverseBytes |= (byte)(((p_Byte >> 2) & 0x01) << 5);
            _ReverseBytes |= (byte)(((p_Byte >> 3) & 0x01) << 4);
            _ReverseBytes |= (byte)(((p_Byte >> 4) & 0x01) << 3);
            _ReverseBytes |= (byte)(((p_Byte >> 5) & 0x01) << 2);
            _ReverseBytes |= (byte)(((p_Byte >> 6) & 0x01) << 1);
            _ReverseBytes |= (byte)(((p_Byte >> 7) & 0x01) << 0);

            return _ReverseBytes;
        }

    }
}

C#直连UVC摄像头底层控制实战指南 UVC(USB Video Class)是USB外设中广泛使用的视频设备标准协议,其核心价值在于标准化的硬件控制能力。理解UVC协议需掌握Control Transfer机制、描述符解析与类请求(如SET_CUR/GET_CUR)原理,这决定了开发者能否绕过Windows默认驱动,实现曝光、白平衡等精准参数调控。技术价值体现在轻量、低依赖、高实时性,适用于工业HMI、AOI检测、医疗设备等严苛场景。C#作为主流上位机语言,需借助libusb等库突破.NET原生限制,完成USB底层通信封装。本文聚焦Sharp 阅读详情

相关推荐

c# 设置窗体和系统的光标形状(使用cur或png)

1、使用自制光标(cur)设置光标形状 2、使用cur文件设置和取消窗体光标形状 3、使用png文件设置和取消窗体光标形状 4、设置和取消系统光标形状

C# 制作ANI动画光标的类

测试代码   private void Form2_Load(object sender, EventArgs e)        {            byte _ValueChar = (byte)A;            Zgke.MyImage.ImageFile.ImageAni _Ani = new Zgke.MyImage.ImageFile.ImageAni();

Zgke 3448

鼠标资源 cur文件,c#等代码中都可以调用.很有用

鼠标资源 cur 文件,c#等代码中都可以调用.很有用 如果大家还有好的,都拿来共享哦.

C#制作透明色GIF动画的类

前几天,关注了下GIF的文件结构 发现一个GIF文件大小错很多.发现主要是3个地方的问题.一是色彩表的问题.GIF有全局色彩表和图形色彩表.二是GIF图形的大小并不一定是一样的 桢1可能是100*100的 桢2可能是10*10 比如天空是黑色100*100 星星在是10*10 三是描述区,没什么作用就是描述 图形一样大小不一样的就这两个地方区别大. 用C#来实现下

Zgke 1万+

鼠标包125个鼠标,cur文件

可以将cur嵌入资源文件进行调用,实现自定义鼠标

C# 绘制鼠标Cur (图像操作)

C# 绘制鼠标Cur (图像操作)

C# 实现渐变透明图片

使用方式   Bitmap _Bitmap = (Bitmap)Image.FromFile(@"c:/1.jpg");            pictureBox3.Image = _Bitmap;            Bitmap _NewBitmap1 = Zgke.MyImage.Panit.Impression.BothAlpha(_Bitmap, false, false

Zgke 7606

C#绘制鼠标Cur图标

摘要:C#源码,图形图像,鼠标图标  C#绘制鼠标Cur图标,具体原理暂时没有详细描述,可以绘制出鼠标的图标图形,CUR文件,源码简单可编译,测试运行界面请参见截图。

[C#]光标(cur/ani)转图片(Image)

光标转图片用C#方法做个记录: System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon("***.cur"); Image img = Image.FromHbitmap(icon.ToBitmap().GetHbitmap());

luols的专栏 3441

跨阻放大器TIA设计实战:从光电二极管等效模型到PCB布局

在光电检测系统中,光电二极管输出的微弱电流信号往往只有纳安级,直接处理极易被噪声淹没。跨阻放大器(TIA)正是解决这一难题的核心电路,其通过运算放大器与反馈电阻的配合,将光电流精确转换为可用电压。理解光电二极管的等效模型、反馈电阻与带宽的博弈关系,以及稳定性补偿和噪声评估,是设计高性能TIA的关键。从环境光传感器到光纤通信接收,TIA的应用贯穿多个领域,而运放选型与PCB布局的细节直接影响最终性能。本文围绕这一工程实践,系统梳理了从参数计算、稳定性分析到调试方法的完整链路,帮助硬件工程师快速掌握跨阻放大电路

weixin_33906657的博客 393

5分钟搞懂知识抽取:如何把非结构化数据变成知识图谱的宝藏?

本文通过一个电商评论分析实战案例,详细解析了如何利用spaCy、Neo4j等工具,将非结构化文本数据转化为结构化知识图谱的完整流程。文章重点阐述了知识抽取的核心步骤,包括命名实体识别、关系抽取以及知识存储与查询,帮助读者快速掌握将数据转化为知识宝藏的关键技术。

weixin_29054245的博客 238

C#中自定义光标之引用 嵌入的资源 的cur文件

初学C#,引入一个生成操作为 嵌入的资源 的cur文件也花了九牛二虎之力,官方MSDN说的太简单,项目结构比较复杂,造成我么样引用都报错,最后终于找到了答案,分享一下:   把*.cur加入到项目里面,设置属性"生成操作"为"嵌入的资源"。       try        {                   this.Cursor   =   new   Cursor(Get...

Rocye的专栏 2123

一文告诉你:如何在trae中编译运行STM32程序,并让AI帮你修改代码

本文详细介绍了如何将STM32程序从Keil迁移到国产免费工具Trae,并利用AI进行代码修改的全过程。

水滴爬呀爬 4985

c# 加载cur 图标失败,其他方法 加载自定义 curt 图标

Bitmap bm = (Bitmap)Image.FromFile(@"D:\名称.png"); this.Cursor = new Cursor(bm.GetHicon()); 转载于:https://www.cnblogs.com/-zss/p/3848997.html

weixin_30293079的博客 235

Zotero PDF Translate插件实战:DeepL API免费申请与高效翻译配置指南

本文提供Zotero PDF Translate插件配置DeepL API的完整实战指南。详细介绍了如何免费申请DeepL API密钥,解决国内访问问题,并在插件中完成精细配置,实现文献阅读时的无缝划词翻译,大幅提升科研人员和学生的英文文献阅读效率。

rum55的博客 483

使用abagen工具箱获取基于脑区的基因表达矩阵

脑区模板定义了您感兴趣的脑区的空间位置。abagen提供了一些预定义的脑区模板,您可以选择使用,也可以使用自定义的脑区模板。它提供了一种简便的方式来获取基于脑区的基因表达矩阵。abagen需要使用Allen脑图谱数据来获取基因表达矩阵。您可以使用abagen内置的下载功能来获取这些数据。这就是使用abagen工具箱获取基于脑区的基因表达矩阵的详细步骤。通过按照上述步骤操作,您可以轻松获取并使用Allen脑图谱数据中的基因表达信息。一旦您加载了脑区模板,您可以使用abagen来获取基于脑区的基因表达矩阵。

web_bug407的博客 1331

C语言 实现带透明度的鼠标光标 .cur 编辑器

有一个bug,就是取色在绘图板上取色时,取到的颜色的透明度是0,也就是说,同样的颜色,有的是透明出来的,有的就是本身的颜色。但是不打算改了,这样的具有启发的BUG就留作纪念,如果想取色带透明度,可以在直接定位到代码里的 mesh 数组,这个数组里存着网格的32位带透明通道的颜色,获取当前像素颜色,就可以直接变成读取所在数组的颜色。增加了滑块修改透明度。

a1309602336的博客 1406

EM的理论与实践(基础篇)

EM理论与实践

m0_61544122的博客 2425

C# WebService调用打印机打印水晶报表。

当初做WINCE程序时,需要通过webservice调用打印机 来打印, 中间传了一些参数取数据,用到水晶报表 架构:VS2005+WINCE5+ORACLE9I +水晶报表 public int PrintLabel(string doc52no,string printername,string rfno,int p_uid,out string errmsg) {

2208

ChatGPT充值,银行卡被拒绝,图文教程

ChatGPT充值,银行卡被拒绝

weixin_46713695的博客 2万+

基于STM32L4XX、HAL库的AD7768BSTZ 模数转换器ADC驱动程序设计

/ 默认SPI配置。// 读取通道数据命令。// 通过SYNC_IN引脚触发转换(如果使用)// 处理数据...// 或者通过SPI命令。// 初始化AD7768。// SPI1引脚配置。

zhusl6688的博客 468

java fseek_fseek里有java吗

java中有类似fseek函数吗,我要回退一个字符(词法现在的百度知道不能关闭问题 你已经把正确答案写出来了,这是很好的习惯。fseek,fscanf,fprintf在代码里写的语句怎么用fseek(fp,0L,0),//fp重新指向文件开始,等于rewind(fp) fscanf(fp,"%d",&k) //从fp中取出一个整数赋值给k fprintf(fp,"%d\n",a[i]+k)...

ぃ妖气ぅ的博客 196

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

ProcessDB实时/时序数据库——C#检索测点信息

ProcessDB实时/时序数据库支持C#语言开发,本文将针对C#操作ProcessDB检索测点信息进行介绍

sun_race的专栏 308

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[C#语言]反转链表

如当输入链表{1,2,3}时,经反转后,原链表变为{3,2,1},所以对应的输出为{3,2,1}。

qq_43559301的博客 423

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

WinCE 文件操作(引用)

WinCE文件操作(引用)<br />常用的三种方法,归纳如下:<br />方法一 使用MFC的CFile类<br />     打开用Open,关闭用Close(),文件指针移动用Seek,读文件用Read(),写文件用Write,获取文件属性可以使用GetFileStatus方法,这个可以查看MSDN,下面给几行简单代码:CFile file; bool isOpenOK = file.Open(L"//flash disk//flyfox//test.txt", CFile::typeBinary|

WaveYang的专栏 1095
上一篇: C# 读写 Photoshop PSD文件 操作类
下一篇: C# 制作ANI动画光标的类
zgke
博客等级 码龄25年 560粉丝 95原创
评论 13
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值