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


C# ImageData.ToBitmap方法代码示例

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


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

示例1: getTransformedBitmap

        private Bitmap getTransformedBitmap()
        {
            if (srcH == 0 || srcW == 0) return null;

            if (rect.Width < 800 && rect.Height < 600)
            {
                ImageData destCB = new ImageData();
                destCB.A = new byte[rect.Width, rect.Height];
                destCB.B = new byte[rect.Width, rect.Height];
                destCB.G = new byte[rect.Width, rect.Height];
                destCB.R = new byte[rect.Width, rect.Height];

                PointF ptInPlane = new PointF();
                int x1, x2, y1, y2;
                double dab, dbc, dcd, dda;
                float dx1, dx2, dy1, dy2, dx1y1, dx1y2, dx2y1, dx2y2, nbyte;

                for (int y = 0; y < rect.Height; y++)
                {
                    for (int x = 0; x < rect.Width; x++)
                    {
                        Point srcPt = new Point(x, y);
                        srcPt.Offset(this.rect.Location);

                        if (isOnPlaneABCD(srcPt))
                        {
                            dab = Math.Abs((new YLScsDrawing.Geometry.Vector(vertex[0], srcPt)).CrossProduct(AB));
                            dbc = Math.Abs((new YLScsDrawing.Geometry.Vector(vertex[1], srcPt)).CrossProduct(BC));
                            dcd = Math.Abs((new YLScsDrawing.Geometry.Vector(vertex[2], srcPt)).CrossProduct(CD));
                            dda = Math.Abs((new YLScsDrawing.Geometry.Vector(vertex[3], srcPt)).CrossProduct(DA));
                            ptInPlane.X = (float)(srcW * (dda / (dda + dbc)));
                            ptInPlane.Y = (float)(srcH * (dab / (dab + dcd)));

                            x1 = (int)ptInPlane.X;
                            y1 = (int)ptInPlane.Y;

                            if (x1 >= 0 && x1 < srcW && y1 >= 0 && y1 < srcH)
                            {
                                if (isBilinear)
                                {
                                    x2 = (x1 == srcW - 1) ? x1 : x1 + 1;
                                    y2 = (y1 == srcH - 1) ? y1 : y1 + 1;

                                    dx1 = ptInPlane.X - (float)x1;
                                    if (dx1 < 0) dx1 = 0;
                                    dx1 = 1f - dx1;
                                    dx2 = 1f - dx1;
                                    dy1 = ptInPlane.Y - (float)y1;
                                    if (dy1 < 0) dy1 = 0;
                                    dy1 = 1f - dy1;
                                    dy2 = 1f - dy1;

                                    dx1y1 = dx1 * dy1;
                                    dx1y2 = dx1 * dy2;
                                    dx2y1 = dx2 * dy1;
                                    dx2y2 = dx2 * dy2;

                                    nbyte = srcCB.A[x1, y1] * dx1y1 + srcCB.A[x2, y1] * dx2y1 + srcCB.A[x1, y2] * dx1y2 + srcCB.A[x2, y2] * dx2y2;
                                    destCB.A[x, y] = (byte)nbyte;
                                    nbyte = srcCB.B[x1, y1] * dx1y1 + srcCB.B[x2, y1] * dx2y1 + srcCB.B[x1, y2] * dx1y2 + srcCB.B[x2, y2] * dx2y2;
                                    destCB.B[x, y] = (byte)nbyte;
                                    nbyte = srcCB.G[x1, y1] * dx1y1 + srcCB.G[x2, y1] * dx2y1 + srcCB.G[x1, y2] * dx1y2 + srcCB.G[x2, y2] * dx2y2;
                                    destCB.G[x, y] = (byte)nbyte;
                                    nbyte = srcCB.R[x1, y1] * dx1y1 + srcCB.R[x2, y1] * dx2y1 + srcCB.R[x1, y2] * dx1y2 + srcCB.R[x2, y2] * dx2y2;
                                    destCB.R[x, y] = (byte)nbyte;
                                }
                                else
                                {
                                    destCB.A[x, y] = srcCB.A[x1, y1];
                                    destCB.B[x, y] = srcCB.B[x1, y1];
                                    destCB.G[x, y] = srcCB.G[x1, y1];
                                    destCB.R[x, y] = srcCB.R[x1, y1];
                                }
                            }
                        }
                    }
                }
                return destCB.ToBitmap();
            }
            else
            {
                return error;
            }
        }
开发者ID:emcf,项目名称:WolfEngine,代码行数:84,代码来源:FreeTransform.cs


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