Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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
C# 将图像转换为base64并设置图像的最大宽度和最大高度_C#_Html_Asp.net - Fatal编程技术网

C# 将图像转换为base64并设置图像的最大宽度和最大高度

C# 将图像转换为base64并设置图像的最大宽度和最大高度,c#,html,asp.net,C#,Html,Asp.net,我在服务器上运行了一个镜像,id=>myImageId,镜像src位于base64 var convertedImage = Convert.ToBase64String( File.ReadAllBytes(somePath), ); myImageId.Src = @"data:image/gif;base64," + convertedImage ; 如果这个图像非常大(max_width=400;max_heigh

我在服务器上运行了一个镜像,id=>myImageId,镜像src位于base64

var convertedImage = Convert.ToBase64String(
                    File.ReadAllBytes(somePath),
                );
myImageId.Src = @"data:image/gif;base64," + convertedImage ;
如果这个图像非常大(max_width=400;max_height=400),我想调整它的大小,在aspx页面中,我可以设置属性“
max width
”和“
max_height
”,但转换后的图像分辨率相同,在转换到基64之前如何调整图像大小以设置最大宽度和高度

如何在转换为base 64之前调整图像大小

不将文件直接传递给Convert.ToBase64String(),而是将其作为图像加载并首先调整其大小

请参阅从文件创建
图像
实例,请参阅获取调整大小的
位图
实例,并请参阅将该位图转换为可馈送到
convert.ToBase64String
的字节数组

然后,您将需要查看缓存,因为您不想在每次请求时调整图像的大小。最好将调整大小和缓存代码结合起来,以最小化所需的代码量并优化互操作性。图书馆的存在就是为了帮你做到这一点。阅读更多信息