Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

bitmap to imagesource c#

    //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); }               
    }
Comment

c# convert bitmap to image

Bitmap inherits from System.Drawing.Image
Comment

PREVIOUS NEXT
Code Example
Csharp :: get list of constants in class c# 
Csharp :: dotnet create web api 
Csharp :: serialize object to json 
Csharp :: reflection get enum value C# 
Csharp :: c# return values 
Csharp :: crud operation in asp.net 
Csharp :: value is null to insert in c# 
Csharp :: c# array lenght 
Csharp :: DateTime restrictions 
Csharp :: asp.net web forms 
Csharp :: static keyword 
Csharp :: binary tree c# 
Csharp :: while loop in c# 
Csharp :: wpf app transparent background with blurred image affect 
Csharp :: exit form esc winforms 
Csharp :: how to instantiate more enemies in unity 
Csharp :: iserviceprovider vs iservicecollection 
Csharp :: list of vectors c# 
Csharp :: remove loading bars devexpress on callback 
Csharp :: blazor editform empty 
Csharp :: ef6 export update 
Csharp :: deploy c# applications on ubuntu 
Csharp :: unity time.fixeddeltatime 
Csharp :: how to change font text mesh pro 
Csharp :: Query Parent-GrandChild collection 
Csharp :: How to add a button to a column in the DataGridView 
Csharp :: autoclicker for yes/no in c# indicator 
Csharp :: How to execute a script after the c# function executed 
Csharp :: open full screen wpf 
Csharp :: c# read csv file save to database dynamically 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =