Bitmap.Compress() 使用哪个流?

Which stream is used with Bitmap.Compress()?

我尝试将位图压缩成 Jpeg,但似乎我可以传递给 Compress 的唯一流是 System.IO 流。

System.IO.Stream s = new System.IO.Stream();
bmpObj.Compress(Bitmap.CompressFormat.Jpeg, 100, s);

正确的方法是什么,使用哪个流?

Stream 是抽象的 class - 您需要使用像 MemoryStreamFileStream

这样的具体实例
using (System.IO.Stream outStream = System.IO.File.Create(targetFile))
{
  bmpObj.Compress(Bitmap.CompressFormat.Png, 100, outStream);
}