Click here to Skip to main content
15,065,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert an image file to Bitmap.
I am not able to convert.
I tried this:

Bitmap(ImageFile)
Posted

Try below one.

private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
    // BitmapImage bitmapImage = new BitmapImage(new Uri("../Images/test.png", UriKind.Relative));

    using(MemoryStream outStream = new MemoryStream())
    {
        BitmapEncoder enc = new BmpBitmapEncoder();
        enc.Frames.Add(BitmapFrame.Create(bitmapImage));
        enc.Save(outStream);
        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);

        // return bitmap; <-- leads to problems, stream is closed/closing ...
        return new Bitmap(bitmap);
    }
}


For more info : Converting BitmapImage to Bitmap and vice versa

I hope this will help to you.
   
This is done for me...
Bitmap bm = new Bitmap(path+filename+".jpg");
   
A similar question was asked here[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900