当前位置: 首页>>代码示例>>C#>>正文


C# RGBA_Bytes.GetAsRGBA_Floats方法代码示例

本文整理汇总了C#中RGBA_Bytes.GetAsRGBA_Floats方法的典型用法代码示例。如果您正苦于以下问题:C# RGBA_Bytes.GetAsRGBA_Floats方法的具体用法?C# RGBA_Bytes.GetAsRGBA_Floats怎么用?C# RGBA_Bytes.GetAsRGBA_Floats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RGBA_Bytes的用法示例。


在下文中一共展示了RGBA_Bytes.GetAsRGBA_Floats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertBitmapToImage

        private static bool ConvertBitmapToImage(ImageBuffer destImage, Bitmap m_WidowsBitmap)
        {
            if (m_WidowsBitmap != null)
            {
                switch (m_WidowsBitmap.PixelFormat)
                {
                    case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
                        {
                            destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);
                            if (destImage.GetRecieveBlender() == null)
                            {
                                destImage.SetRecieveBlender(new BlenderBGRA());
                            }

                            BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
                            int sourceIndex = 0;
                            int destIndex = 0;
                            unsafe
                            {
                                int offset;
                                byte[] destBuffer = destImage.GetBuffer(out offset);
                                byte* pSourceBuffer = (byte*)bitmapData.Scan0;
                                for (int y = 0; y < destImage.Height; y++)
                                {
                                    destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
                                    for (int x = 0; x < destImage.Width; x++)
                                    {
#if true
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
#else
                                            RGBA_Bytes notPreMultiplied = new RGBA_Bytes(pSourceBuffer[sourceIndex + 0], pSourceBuffer[sourceIndex + 1], pSourceBuffer[sourceIndex + 2], pSourceBuffer[sourceIndex + 3]);
                                            sourceIndex += 4;
                                            RGBA_Bytes preMultiplied = notPreMultiplied.GetAsRGBA_Floats().premultiply().GetAsRGBA_Bytes();
                                            destBuffer[destIndex++] = preMultiplied.blue;
                                            destBuffer[destIndex++] = preMultiplied.green;
                                            destBuffer[destIndex++] = preMultiplied.red;
                                            destBuffer[destIndex++] = preMultiplied.alpha;
#endif
                                    }
                                }
                            }

                            m_WidowsBitmap.UnlockBits(bitmapData);

                            return true;
                        }

                    case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
                        {
                            destImage.Allocate(m_WidowsBitmap.Width, m_WidowsBitmap.Height, m_WidowsBitmap.Width * 4, 32);

                            BitmapData bitmapData = m_WidowsBitmap.LockBits(new Rectangle(0, 0, m_WidowsBitmap.Width, m_WidowsBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, m_WidowsBitmap.PixelFormat);
                            int sourceIndex = 0;
                            int destIndex = 0;
                            unsafe
                            {
                                int offset;
                                byte[] destBuffer = destImage.GetBuffer(out offset);
                                byte* pSourceBuffer = (byte*)bitmapData.Scan0;
                                for (int y = 0; y < destImage.Height; y++)
                                {
                                    sourceIndex = y * bitmapData.Stride;
                                    destIndex = destImage.GetBufferOffsetXY(0, destImage.Height - 1 - y);
                                    for (int x = 0; x < destImage.Width; x++)
                                    {
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = pSourceBuffer[sourceIndex++];
                                        destBuffer[destIndex++] = 255;
                                    }
                                }
                            }

                            m_WidowsBitmap.UnlockBits(bitmapData);
                            return true;
                        }

                    case System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
                        {
                            Copy8BitDataToImage(destImage, m_WidowsBitmap);
                            return true;
                        }

                    default:
                        throw new System.NotImplementedException();
                }

            }
            return false;
        }
开发者ID:jeske,项目名称:agg-sharp,代码行数:93,代码来源:ImageIOWindowsPlugin.cs


注:本文中的RGBA_Bytes.GetAsRGBA_Floats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。