如何从图形类中获取图像流
本文关键字:获取 图像 图形 | 更新日期: 2023-09-27 18:26:10
我想保存从图形类创建的图像,怎么做?(如果我能得到图像流,那么我可以使用下面的代码)
var bmp = Bitmap.FromStream(originalStream);
// var newImage = new Bitmap(bmp.Width, bmp.Height);
var img = new Bitmap(bmp,
(int)(bmp.Size.Width / zoomLevel),
(int)(bmp.Size.Height / zoomLevel));
var g = Graphics.FromImage(img);
g.DrawImageUnscaled(bmp, (int)CurrentX, (int)CurrentY);
g.DrawString(Text, SystemFonts.DefaultFont, Brushes.Black, (float)CurrentTextX, (float)CurrentTextY);
string originalImagePath = string.Concat(@"Photos/", string.Format("{0:yyyy-MM-dd}", ApplicationDateTime.Today) + "/" + Session[Keys.UserId], "/", url.Split('/').Last());
var originalImageamazonResponse = _s3AmazonServices.StoreImage(originalStream, originalImagePath, Configuration.ConfigurationNew.Current.S3Bucket, Configuration.ConfigurationNew.Current.S3AmazonAccessKey, Configuration.ConfigurationNew.Current.S3AmazonSecretKey);
我相信img
会随着您对从中创建的g
所做的一切而被修改。因此,您应该能够调用img.Save()
。