您的位置:程序门 -> .net技术 -> c#



图像框选放大和缩小(在线等)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


图像框选放大和缩小(在线等)[已结贴,结贴人:geoffe]
发表于:2007-01-24 14:57:58 楼主
如何实现框选图片的某个部位
然后放大或者缩小?高手指点,急用
发表于:2007-01-24 15:21:401楼 得分:0
帮顶   我也想知道

picturebox.image.height   和   width都是只读的

我还想知道   怎么给picturebox做一个滚动条   我不想做sizemode   =   zoom
发表于:2007-01-24 15:42:082楼 得分:50
框选
private   graphicspath   gp   =   new   graphicspath();

mousemove:

                      preview.refresh();
                        gp.reset();
                        gp.addrectangle(new   rectangle(p0.x,   p0.y,   math.abs(p0.x   -   p1.x),   math.abs(p0.y   -   p1.y)));
                        graphics   g   =   preview.creategraphics();
                        pen   pen   =   new   pen(color.red,   1.0f);
                        g.drawpath(pen,   gp);
                        g.dispose();


mousedown:
                        preview.refresh();
                        gp.reset();

需要注意处理起始点和终止点的位置问题(比如,用户从右下拖到左上)


框选好以后你可以用graphics类的drawimage得到框选好的图像。同样还是drawimage实现放大缩小。

//剪裁
              public   static   bitmap   kicut(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);

                        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;
                }


//重设大小
                public   static   bitmap   kiresizeimage(bitmap   bmp,   int   neww,   int   newh)
                {
                        try
                        {
                                bitmap   b   =   new   bitmap(neww,   newh);
                                graphics   g   =   graphics.fromimage(b);

                                //强制用效果最好的插值算法
                                g.interpolationmode   =   interpolationmode.highqualitybicubic;

                                g.drawimage(bmp,   new   rectangle(0,   0,   neww,   newh),   new   rectangle(0,   0,   bmp.width,   bmp.height),   graphicsunit.pixel);
                                g.dispose();

                                return   b;
                        }
                        catch
                        {
                                return   null;
                        }
                }


需要的话,最后再把得到的bitmap重新画到picturebox里。
发表于:2007-01-24 16:11:523楼 得分:0
看看
发表于:2007-01-24 16:14:384楼 得分:0
非常感谢
发表于:2007-09-23 10:43:065楼 得分:0
picturebox控件,acdsee控件,图片控件;
用c#开发的图片控件,功能类似acdsee;
支持各种图片的浏览,放大,缩小,平移等功能;
源代码参考:http://shop.paipai.com/359073000


快速检索

最新资讯
热门点击