Okay I figured this out - Basically I added a new method called "setScaleBar" modeled after the "setMap" method.
public class PDFExporter
{
private IParentDialog _Parent = null;
private Map _Map = null;
private ScaleBar _ScaleBar = null;
private Stream _streamOutPDF = null;
private WriteableBitmap _wbm;
private bool _bAsync = false;
private int _iLayer;
private double _dOpacity;
private List<UIElement> _ElementList = new List<UIElement>();
public void SetParent(IParentDialog TheParent)
{
_Parent = TheParent;
}
public void SetMap(Map TheMap)
{
_Map = TheMap;
}
public void SetScaleBar(ScaleBar TheScaleBar)
{
_ScaleBar = TheScaleBar;
}
...
Next I modified the "Bitmap2Stream" method so that it passed in the WriteableBitMap and returned the stream (this made this routine more reusable):
private Stream Bitmap2Stream(ref WriteableBitmap wbmp)
{
// Convert bitmap to byte array used by encoder
Stream bmpstream;
int iWidth = wbmp.PixelWidth;
int iRowLen = (iWidth * 4) + 1;
int iHeight = wbmp.PixelHeight;
int[] pixels = wbmp.Pixels;
byte[] bytes = new byte[iRowLen * iHeight];
int iRow, iCol, i, j, pixel;
byte R, G, B, A;
for (iRow = 0; iRow < iHeight; iRow++)
{
bytes[iRow * iRowLen] = 0; // Filter bit
for (iCol = 0; iCol < iWidth; iCol++)
{
i = (iRow * iWidth) + iCol;
pixel = pixels;
R = (byte)((pixel >> 16) & 0xFF);
G = (byte)((pixel >> 😎 & 0xFF);
B = (byte)(pixel & 0xFF);
A = (byte)((pixel >> 24) & 0xFF);
j = (iRow * iRowLen) + (iCol * 4) + 1;
bytes = R;
bytes[j + 1] = G;
bytes[j + 2] = B;
bytes[j + 3] = A;
}
}
// Encode to stream
bmpstream = Silverlight.Samples.PngEncoder.Encode(bytes, iWidth, iHeight);
wbmp = null;
return bmpstream;
}
In the "FinishExport" routine, I modified the call to Bitmap2Stream for the map as so:
_stream = Bitmap2Stream(ref _wbm)
and then added the following logic (bolded):
if (_ScaleBar != null)
{
ScaleTransform transform = new ScaleTransform();
transform.ScaleX = transform.ScaleY = 1.0;
WriteableBitmap wbmpScaleBar = new WriteableBitmap(_ScaleBar, transform);
Stream sbstream = Bitmap2Stream(ref wbmpScaleBar);
XImage sbimg = XImage.FromStream(sbstream);
double sbY = img.PointHeight - sbimg.PointHeight - 5;
gfx.DrawImage(sbimg, 5, sbY, sbimg.PointWidth, sbimg.PointHeight);
}
document.Save(_streamOutPDF);
document.Close();
document = null;
mapstream.Close();
mapstream = null;
_streamOutPDF = null;
MessageBox.Show("PDF created.");