当前位置:编程学习 > C#/ASP.NET >>

C#图像处理问题


部分代码
private static Bitmap Cut(Bitmap b, int StartX, int StartY, int iWidth, int iHeight) 
        { 
            if (b == null)
            { 
                return null;
            } 
            int w = b.Width; 
            int h = b.Height; 
            if (StartX >= w || StartY >= h) 
            { 
                return null; 
            } 
            if (StartX + iWidth > w) 
            { 
                iWidth = w - StartX; 
            } 
            if (StartY + iHeight > h) 
            { 
                iHeight = h - StartY; 
            }
            Bitmap bmpOut = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
            SolidBrush b1 = new SolidBrush(Color.Red);
            //Rectangle rect = new Rectangle();
            using (Graphics g = Graphics.FromImage(bmpOut))
            {
                TextureBrush b2 = new TextureBrush(Image.FromFile(Application.StartupPath + "\\cm.png"));
                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
                for (int i = 0; i < 22; i++)
                {
                    if (data.Yzcode[i] > 0)
                    {
                        Point pbuton = (Point)CMlist[i];
                        /*for (int j = 0; j < data.Yzcode[i] / 10; j++) 
                        {
                            pbuton.Y = pbuton.Y - j;
                            rect.Location = pbuton;//更改这个矩形的起点坐标
                            b2.TranslateTransform(pbuton.X, pbuton.Y);
                            rect.Width = b2.Image.Width;//更改这个矩形的宽来
                            rect.Height = b2.Image.Height;//更改这个矩形的高
                            g.FillRectangle(b2, rect);
                        }*/
                        //b2.Transform.
                        //rect.Location = pbuton;//更改这个矩形的起点坐标
                        b2.TranslateTransform(pbuton.X, pbuton.Y);
                        //rect.Width = 52;//更改这个矩形的宽来
                        //rect.Height = 33;//更改这个矩形的高
                        g.FillRectangle(b2, pbuton.X,pbuton.Y,52,33);
                        g.DrawString(data.Yzcode[i].ToString(), new Font("宋体", 10), b1, new PointF(pbuton.X + 10, pbuton.Y + 6));
                    }
                }
                /*Point pbuton = new Point();
                TextureBrush b2 = new TextureBrush(Image.FromFile(Application.StartupPath + "\\cm.png"));
                rect.Location = pbuton;//更改这个矩形的起点坐标
                b2.TranslateTransform(pbuton.X, pbuton.Y);
                rect.Width = b2.Image.Width;//更改这个矩形的宽来
                rect.Height = b2.Image.Height;//更改这个矩形的高
                g.FillRectangle(b2, rect);
                g.DrawString("100", new Font("宋体", 10), b1, new PointF(pbuton.X + 10, pbuton.Y + 6));*/
                g.Dispose();
                return bmpOut;
            }
            /*try 
            { 
                
                Graphics g = Graphics.FromImage(bmpOut); 
                g.DrawImage(b, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(StartX, StartY, iWidth, iHeight), GraphicsUnit.Pixel);
                g.Dispose(); 
                return bmpOut; 
            } 
            catch { return null; }*/
        }

这是先从内存中载入一张图片,然后动态画到画布上出现图片不完整 图像处理 Bitmap C#
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,