クリップボードの内容を共有できるクライアント サーバー プログラムを実行しようとしています。
クリップボードに画像が含まれていると問題が発生しました。BitmapSource をバイト配列にエンコードして送信し、デコードしてサーバーのクリップボードに挿入することができます。しかし、クリップボードをペイントや Gimp などのプログラムに貼り付けようとすると、データが認識されないためエラーが発生します。
これはクライアント コードです。
if (Clipboard.ContainsImage())
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(Clipboard.GetImage()));
using (MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
return ms.ToArray();
}
}
これはサーバーコードです:
JpegBitmapDecoder jpegd = null;
using (MemoryStream ms = new MemoryStream(b)) // b is the byte array received from the client
{
jpegd = new JpegBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
}
BitmapSource bitmapSource = jpegd.Frames[0];
// Inject data into the clipboard
Clipboard.SetImage(bitmapSource);