WPF – converting Bitmap to ImageSource

For others, this works: //If you get ‘dllimport unknown’-, then add ‘using System.Runtime.InteropServices;’ [DllImport(“gdi32.dll”, EntryPoint = “DeleteObject”)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteObject([In] IntPtr hObject); public ImageSource ImageSourceFromBitmap(Bitmap bmp) { var handle = bmp.GetHbitmap(); try { return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } finally { DeleteObject(handle); } }

How to convert int to string in C++

C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string. #include <string> std::string s = std::to_string(42); is therefore the shortest way I can think of. You can even omit naming the type, using the auto keyword: auto s = std::to_string(42); … Read more