0

i needed to send bitmap into my chat application soo my idea was save it into a temporaty folder and from there upload it like my drag and drop image thats already working. but when it saves the bitmap in windows fileviewer i can see thumbnail but everywhere else its empty any idea where the problem could be or how to do this any better way? thanks in advance. here is a video so you can better understand ^^ https://youtu.be/p0t2byTRN58

string temp = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName + @"\Luxray\" + @"\clipboardimg.png";
if (File.Exists(temp))
{
    File.Delete(temp);
}
BitmapSource bmpSource = Clipboard.GetImage();
MemoryStream ms = new MemoryStream();
FileStream stream = new FileStream(temp, FileMode.Create);
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmpSource));
encoder.Save(stream);
stream.Close();

this code runs right after if statment that checks if clipboard has bitmap inside and ctrl+v was pressed in the video it is after msgbox with "img sent" pops up.

Just 8
  • 3
  • 2

1 Answers1

0

What are you trying to achieve? if you're trying to save a clipboard image to file the below code works for me:

var img = System.Windows.Forms.Clipboard.GetImage();
img.Save(savePath, ImageFormat.Png);
  • 1
    awww it was so simple i dont know how i missed this solution. thank you very much ^^. – Just 8 Oct 03 '18 at 11:18
  • If you want transparency support in the image, the answer is [a bit more complicated](https://stackoverflow.com/a/46424800/395685), though. (Also note that that answer is not WPF and uses `System.Drawing`.) – Nyerguds Oct 09 '18 at 09:32