Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net c#将文件流转换为图像_C#_Asp.net_Filestream - Fatal编程技术网

asp.net c#将文件流转换为图像

asp.net c#将文件流转换为图像,c#,asp.net,filestream,C#,Asp.net,Filestream,我有一个文件流,我正试图转换成一个图像。我有以下代码 FileStream imageFile = image["file"] as FileStream; 图像是包含图像信息的地图。请有人告诉我下一步该做什么。Image。FromStream将获取一个流并返回一个图像。顺便说一句,如果您使用Bitmap.FromStream或Image.FromStream,或者确实使用这些方法中的任何一种,它们都会返回一个位图,因此如果您愿意,它们都可以从Image向上转换为位图。您可以执行以下操作:

我有一个文件流,我正试图转换成一个图像。我有以下代码

FileStream imageFile = image["file"] as FileStream;

图像是包含图像信息的地图。请有人告诉我下一步该做什么。

Image。FromStream
将获取一个流并返回一个图像。顺便说一句,如果您使用
Bitmap.FromStream
Image.FromStream
,或者确实使用这些方法中的任何一种,它们都会返回一个
位图
,因此如果您愿意,它们都可以从
Image
向上转换为
位图

您可以执行以下操作:

        int width = 128;
        int height = width;
        int stride = width / 8;
        byte[] pixels = new byte[height * stride];

        // Define the image palette
        BitmapPalette myPalette = BitmapPalettes.Halftone256;

        // Creates a new empty image with the pre-defined palette
        BitmapSource image = BitmapSource.Create(
            width,
            height,
            96,
            96,
            PixelFormats.Indexed1,
            myPalette,
            pixels,
            stride);

        FileStream stream = new FileStream("new.jpg", FileMode.Create);
        JpegBitmapEncoder encoder = new JpegBitmapEncoder();
        encoder.FlipHorizontal = true;
        encoder.FlipVertical = false;
        encoder.QualityLevel = 30;
        encoder.Rotation = Rotation.Rotate90;
        encoder.Frames.Add(BitmapFrame.Create(image));
        encoder.Save(stream);

为什么要复制
图像
变量名?我怀疑你会编译什么。你说的“转换为图像”是什么意思?你的意思是将它转换成
位图
实例,还是响应图像请求将其提供给客户端?图像位于服务器上,我使用文件流获取它,目的是在网页上显示图像。