Skip to main content

Answered Question Convert writableBitmap to jpeg using FJCore in SL3 RTWRSS Feed

(0)

TomGiam
TomGiam

Participant

Participant

852 points

246 Posts

Convert writableBitmap to jpeg using FJCore in SL3 RTW

Anybody figured out how to convert a Writablebitmap to a jpeg using JFCore?

I want to save it to disk or send it to the server.

Thanks

Tom

 

TomGiam
TomGiam

Participant

Participant

852 points

246 Posts

Re: Convert writableBitmap to jpeg using FJCore in SL3 RTW

I can now convert any UIElement to PNG and save to the local computer.

Note that: images need to be from the same domain as the SL application is launched from.

I would appreciate it if someone can show me how to do the same with JPG.

It should be possible with FJCore or some other jpeg encoder.

Most of the information and associated files came from here:

http://www.andybeaulieu.com/Home/tabid/67/EntryID/161/Default.aspx

 

Thanks

Tom

 

private void Save_As_Image_Click(object sender, RoutedEventArgs e)

{

SaveFileDialog sfd = new SaveFileDialog()

{

DefaultExt =
"png",Filter = "Png files (*.png)|*.png|All files (*.*)|*.*",

FilterIndex = 1

};

if (sfd.ShowDialog() == true)

{

WriteableBitmap w = new WriteableBitmap(mainPage, new TranslateTransform());

EditableImage imageData = new EditableImage(w.PixelWidth, w.PixelHeight);

try

{

for (int y = 0; y < w.PixelHeight; ++y)

{

for (int x = 0; x < w.PixelWidth; ++x)

{

int pixel = w.Pixels[w.PixelWidth * y + x];

imageData.SetPixel(x, y,

(
byte)((pixel >> 16) & 0xFF),

(byte)((pixel >> 8) & 0xFF),

(byte)(pixel & 0xFF),(byte)((pixel >> 24) & 0xFF)

);

}

}

}

catch (System.Security.SecurityException)

{

Helper.dispMessage("Cannot print images from other domains");return;

}

Stream pngStream = imageData.GetStream();

StreamReader sr = new StreamReader(pngStream);

byte[] binaryData = new Byte[pngStream.Length];

long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);using (Stream stream = sfd.OpenFile())

{

stream.Write(binaryData, 0, binaryData.Length);

stream.Close();

}

}

}

sebschmitt
sebschmitt

Member

Member

20 points

24 Posts

Re: Re: Convert writableBitmap to jpeg using FJCore in SL3 RTW

I'm also interested in the answer to Tom's question (how to convert writeableBitmap to jpeg with FJCore). Any solutions so far?

sebschmitt
sebschmitt

Member

Member

20 points

24 Posts

Answered Question

Re: Re: Re: Convert writableBitmap to jpeg using FJCore in SL3 RTW

 Found the solution here: http://stackoverflow.com/questions/1139200/using-fjcore-to-encode-silverlight-writeablebitmap

jkonline
jkonline

Member

Member

2 points

4 Posts

Re: Re: Re: Convert writableBitmap to jpeg using FJCore in SL3 RTW

 This blog post outlines how do do it.

 http://blog.blueboxes.co.uk/2009/07/21/rendering-xaml-to-a-jpeg-using-silverlight-3/

 

  • Unanswered Question
  • Answered Question
  • Announcement