阅读图像内容 [英] read an image content

查看:80
本文介绍了阅读图像内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用下面的代码创建图像文件

Hi,

I am creating an image file using the code below

Bitmap newImage = new Bitmap(Convert.ToInt32(dtDevice.Rows[0]["LogoWidth"]), Convert.ToInt32(dtDevice.Rows[0]["LogoHeight"]));

                                       using (Graphics gr = Graphics.FromImage(newImage))
                                       {
                                           gr.SmoothingMode = SmoothingMode.AntiAlias;
                                           gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                           gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                                           gr.DrawImage(SourceLogo, new Rectangle(0, 0, Convert.ToInt32(dtDevice.Rows[0]["LogoWidth"].ToString()), Convert.ToInt32(dtDevice.Rows[0]["LogoHeight"].ToString())));
                                       }

                                       fileName = dr["DeviceID"].ToString() + "_" + objBusiness.ID + "_" + objBusiness.ResellerId + imgExtension;

                                       //Save the resized image
                                       newImage.Save(filePath + fileName);





save方法将文件保存在指定的文件夹中。但在保存之前我想获得图像的原始数据。目前正在这样做





The save method saves the file in the specified folder. But before saving i want to get the raw data of the image . Currently am doing this

FileInfo fileInfo = new FileInfo(tempFilePath + fileName);
                                       byte[] fileData = new byte[fileInfo.Length];
                                       DataTable dtBusiness = new Businesses().GetBusiness(objBusiness.ID);
                                       if (dtBusiness != null && dtBusiness.Rows.Count > 0)
                                       {
                                           httpUserName = dtBusiness.Rows[0]["httpUserName"].ToString();
                                           httpPassword = dtBusiness.Rows[0]["httpPassword"].ToString();
                                       }
                                       fileData = File.ReadAllBytes(filePath + fileName);

                                       using (FileStream fs = new FileStream(filePath + fileName, FileMode.Open, FileAccess.Read))
                                       {
                                           fileData = new byte[fs.Length];
                                           fs.Read(fileData, 0, Convert.ToInt32(fs.Length));
                                           fs.Close();
                                       }
                                       imageContent = Convert.ToBase64String(fileData);







因此图像内容将是base64String.But问题是读取文件字节我必须保存它我要跳过。



是否可以在保存到文件夹之前获取它?提前感谢




so that image content will be a base64String.But the problem is that to read the file bytes i have to save it which i want to skip.

Is it possible to get it before saving in the folder?Thanks in advance

推荐答案

原始数据是什么意思?



你可以从这里开始:

位图类 [ ^ ]



并查看哪些属性/方法可以为您提供所需的信息。
What do you mean by raw data?

You could start from here:
Bitmap Class[^]

and see which properties/methods could give you what you want.


嗯,您可以试试这个:

将图像转换为原始二进制数据 [ ^ ]
Well, you can have a try with this one:
Convert Image to "Raw Binary Data"[^]


这篇关于阅读图像内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆