无法从"System.IO.Stream"转换为"System.IO.FileInfo" [英] cannot convert from 'System.IO.Stream' to 'System.IO.FileInfo'
本文介绍了无法从"System.IO.Stream"转换为"System.IO.FileInfo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出现此错误:
方法"ReadJpeg"的不重载带有2个参数
我像这样将WriteableBitmap转换为Stream:
this error is appear :
No overload for method ''ReadJpeg'' takes 2 arguments
i''m convert WriteableBitmap to Stream like this :
WriteableBitmap wb = new WriteableBitmap((int)Camera.PreviewResolution.Width,(int)Camera.PreviewResolution.Height);
Camera.GetPreviewBufferArgb32(pixels);
pixels.CopyTo(wb.Pixels, 0);
var imageStream = new MemoryStream();
Stream myStream = imageStream;
wb.SaveJpeg(myStream , wb.PixelWidth, wb.PixelHeight, 0, 100);
//then I'm write this code to retun angle
int GetAngleFromExif(Stream myStream)
{
var position = myStream.Position;
myStream.Position = 0;
ExifOrientation orientation = ExifReader.ReadJpeg(
myStream, String.Empty).Orientation;
myStream.Position = position;
switch (orientation)
{
case ExifOrientation.TopRight:
return 90;
case ExifOrientation.BottomRight:
return 180;
case ExifOrientation.BottomLeft:
return 270;
case ExifOrientation.TopLeft:
case ExifOrientation.Undefined:
default:
return 0;
}
}
//and tis is the ReadJpeg
public static JpegInfo ReadJpeg(FileInfo fi)
{
DateTime then = DateTime.Now;
using (FileStream fs = fi.OpenRead())
{
ExifReader reader = new ExifReader(fs);
reader.info.FileSize = (int)fi.Length;
reader.info.FileName = fi.Name;
reader.info.LoadTime = (DateTime.Now - then);
return reader.info;
}
}
但是当只传递一个这样的参数时:
but when pass just one arrgument like this :
ExifOrientation orientation = ExifReader.ReadJpeg(
myStream).Orientation;
无法从"System.IO.Stream"转换为"System.IO.FileInfo"
我如何解决此问题
cannot convert from ''System.IO.Stream'' to ''System.IO.FileInfo''
how i can solution this problem
推荐答案
它只是指出没有ReadJpeg
的重载,而ReadJpeg
是以''System.IO.Stream''
作为参数之一.
无论是一个参数还是多个参数,ReadJpeg都希望''System.IO.FileInfo''
作为参数.
您需要传递FileInfo而不将Stream传递给该方法.
It simply states that there is no overload ofReadJpeg
that takes''System.IO.Stream''
as one of the arguments.
Either one paramter or multiple, ReadJpeg expects''System.IO.FileInfo''
as a parameter.
You need to pass FileInfo and not Stream to the method.
由于您正在使用MemoryStream,因此没有文件可以从中获取FileInfo
.
您需要对ReadJpeg
方法进行重载,该方法将采用
Stream
或MemoryStream
作为参数.
Since you''re using MemoryStream, there is no file from which you can getFileInfo
.
You''ll need to make an overload ofReadJpeg
method that will take
Stream
orMemoryStream
as parameter.
public static JpegInfo ReadJpeg(Stream stream)
{
DateTime then = DateTime.Now;
ExifReader reader = new ExifReader(stream);
reader.info.FileSize = stream.Length;
reader.info.LoadTime = (DateTime.Now - then);
return reader.info;
}
这篇关于无法从"System.IO.Stream"转换为"System.IO.FileInfo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文