Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void Capture_Click(object sender, RoutedEventArgs e)
{

WriteableBitmap bitmap = new WriteableBitmap(1920,1080);
//WriteableBitmap bitmap = new WriteableBitmap(sourceElement, null);

if (bitmap != null)
{
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "JPEG Files (*.jpeg)|*.jpeg";
saveDlg.DefaultExt = ".jpeg";

if ((bool)saveDlg.ShowDialog())
{
using (Stream fs = saveDlg.OpenFile())
{

SaveToFile(bitmap, fs);
//MessageBox.Show("Complete");

}
}
}
}

private static void SaveToFile(WriteableBitmap bitmap, Stream fs)
{
int width = bitmap.PixelWidth;
int height = bitmap.PixelHeight;
int bands = 3;
byte[][,] raster = new byte[bands][,];

//Convert the Image to pass into FJCore
//Code From http://stackoverflow.com/questions/1139200/using-fjcore-to-encode-silverlight-writeablebitmap
for (int i = 0; i < bands; i++)
{
raster[i] = new byte[width, height];
}

for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitmap.Pixels[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}



//Encode the Image as a JPEG
MemoryStream stream = new MemoryStream();



//Back to the start
stream.Seek(0, SeekOrigin.Begin);

//Get teh Bytes and write them to the stream
byte[] binaryData = new Byte[stream.Length];
long bytesRead = stream.Read(binaryData, 0, (int)stream.Length);
fs.Write(binaryData, 0, binaryData.Length);
}
Posted
Updated 2-Aug-15 23:32pm
v3

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