• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#图像操作1

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1 显示图片

主要命令:

Image.FromFile();

graphics.DrawImage(image);

 OnPaint(PaintEventArgs paintEvnt)
        {
                     
            Image newImage = Image.FromFile("C:/test.jpg");

            
// 设置图像显示的左上角
            PointF ulCorner = new PointF(10.0F10.0F);

            
// 显示出图片.
            paintEvnt.Graphics.DrawImage(newImage, ulCorner);


        }

 

2 图像缩略图

主要命令:

image.GetThumbnailImage();



        public void ResizeImage(string OrigFile, string NewFile, int NewWidth, int MaxHeight, bool ResizeIfWider)
        {
            System.Drawing.Image FullSizeImage 
= System.Drawing.Image.FromFile(OrigFile);
            
// Ensure the generated thumbnail is not being used by rotating it 360 degrees
            FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullSizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            
if (ResizeIfWider)
            {
                
if (FullSizeImage.Width <= NewWidth)
                {
                    NewWidth 
= FullSizeImage.Width;
                }
            }

            
int NewHeight = FullSizeImage.Height * NewWidth / FullSizeImage.Width;
            
if (NewHeight > MaxHeight) // 如果超出了高度限制,则按高度来缩放
            {
                NewWidth 
= FullSizeImage.Width * MaxHeight / FullSizeImage.Height;
                NewHeight 
= MaxHeight;
            }

            
// 按照计算的数据进行图像缩放
            System.Drawing.Image NewImage = FullSizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
            FullSizeImage.Dispose();
            NewImage.Save(NewFile);
        }

 

3  创建图片文件

主要命令:

Metafile("filename",hdc)。

IntPtr hdc = graphics.GetHdc();

graphics2 = Graphics.FromImage(metaFile);

graphics2.DrawRectangle();

 

 e.Graphics;
            IntPtr hdc = newGraphics.GetHdc();

            
// 新建一个metafile对象来记录.
            Metafile metaFile1 = new Metafile("SampMeta.emf", hdc);
          
            
// 在记录文件上创建一个图画板.
            Graphics metaGraphics = Graphics.FromImage(metaFile1);
            
// 画画.
            metaGraphics.DrawRectangle(new Pen(Color.Black, 5), 1000400400);

            metaGraphics.Dispose();
            metaFile1.Dispose();

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#测试发布时间:2022-07-10
下一篇:
C#中SQLSERVER2008字符数据类型使用心得发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap