Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I need to export a WriteableBitmap that I get after cropping an image. I am not getting how to do that, I am using the following:

C#
try
            {
                byte[] byteStream;
                byteStream = ToByteArray(sample);
                Stream stream = new MemoryStream(byteStream);
                if (filename != null && filename != "")
                {
                    string imgCropFileName = "Crop_" + DateTime.Now.Day + filename;
                    MessageBox.Show("FileName" + " " + imgCropFileName);
                    UploadFile(imgCropFileName, stream);
                }
                else
                    MessageBox.Show("FileName" + " " + filename);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }


In the code segment ToByteArray is a function to convert WriteableBitmap into array of bytes.
For uploading, I am using a generic handler which when hit and get relevant parameters, uploads the file.
Please help me.
Posted
Updated 13-Mar-13 7:49am
v3
Comments
Sergey Alexandrovich Kryukov 13-Mar-13 13:52pm    
I'm just curious: did you try to search for the answer? It could take just a minute to find out...
—SA

1 solution

This is done by a separate class, one of the derived classes based on System.Windows.Media.Imaging.BitmapEncoder. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapencoder.aspx[^].

Actually, this is a very good WFP feature: persistence is isolated from images. If you think about it, you will see that it helps to follow the fundamental OOP development Open/Close Principle:
http://en.wikipedia.org/wiki/Open_Closed_Principle[^].

—SA
 
Share this answer
 
v2

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