Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

c# - Save WriteableBitmap to file using WPF

I have:

WriteableBitmap bmp;

I basicly want to save it into a file on the disk like the following:

C:mp.png

I read some forums which mentions to read:

bmp.Pixels

and save those pixels into a Bitmap then use Bitmap.SaveImage() function. However, I can't access any Pixels. Apperantly my WriteableBitmap does not have any property named Pixels.

I use .NET Framework 4.0.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use your WriteableBitmap's clone and use this function as below:

CreateThumbnail(filename, _frontBitmap.Clone());

...

void CreateThumbnail(string filename, BitmapSource image5)
{
    if (filename != string.Empty)
    {
         using (FileStream stream5 = new FileStream(filename, FileMode.Create))
         {
             PngBitmapEncoder encoder5 = new PngBitmapEncoder();
             encoder5.Frames.Add(BitmapFrame.Create(image5));
             encoder5.Save(stream5);
         }
    }
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...