在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 显示图片 主要命令: Image.FromFile(); graphics.DrawImage(image);
OnPaint(PaintEventArgs paintEvnt)
{ Image newImage = Image.FromFile("C:/test.jpg"); // 设置图像显示的左上角 PointF ulCorner = new PointF(10.0F, 10.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), 100, 0, 400, 400); metaGraphics.Dispose(); metaFile1.Dispose(); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论