13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{//// Set up some <strong>in</strong>ternal variables to determ<strong>in</strong>e// size and position of the bar and the// companion text//// Draw the value (top of the bar)g.DrawStr<strong>in</strong>g(dt.Rows[i][fieldValue].ToStr<strong>in</strong>g(),fnt, textBrush, x, yCaption);// Draw the barRectangle bar = new Rectangle(x, yBarTop, barWidth - 10,barHeight);L<strong>in</strong>earGradientBrush fill = new L<strong>in</strong>earGradientBrush(bar,Color.Spr<strong>in</strong>gGreen, Color.Yellow,L<strong>in</strong>earGradientMode.BackwardDiagonal);g.FillRectangle(fill, bar);fill.Dispose();}// Draw the employee name (bottom of the bar)g.DrawStr<strong>in</strong>g(dt.Rows[i][fieldLabel].ToStr<strong>in</strong>g(),fnt, textBrush, x, barBottom + textHeight);At the end of the loop, the bar chart is completely rendered <strong>in</strong> the Bitmap object. Thebitmap is still held <strong>in</strong> memory <strong>in</strong> an <strong>in</strong>termediate, <strong>in</strong>ternal <strong>for</strong>mat, however. Two moresteps are necessary: convert<strong>in</strong>g the bitmap to a public <strong>for</strong>mat such JPEG, BMP, or GIF,and figur<strong>in</strong>g out a way to persist or transfer its content.Encod<strong>in</strong>g Images as B<strong>in</strong>HexConvert<strong>in</strong>g a Bitmap object to one of the commonly used image <strong>for</strong>mats is a nonissue.You call the Save method on the Bitmap object, pick up one of the supported <strong>for</strong>mats,and you're done. The real difficulty has to do with the planned use of this helper class.Remember, we designed this class <strong>for</strong> later use with<strong>in</strong> a .<strong>NET</strong> Remot<strong>in</strong>g server and aWeb service. When Web services <strong>in</strong> particular are <strong>in</strong>volved, hav<strong>in</strong>g the helper classsave the image to persistent storage just doesn't make sense. An alternative approachwould be sav<strong>in</strong>g the bitmap locally on the server <strong>in</strong> a location accessible <strong>for</strong> downloadvia FTP or HTTP. Creat<strong>in</strong>g files on the server might pose security problems, however,and normally <strong>for</strong>ces the system adm<strong>in</strong>istrator to change default sett<strong>in</strong>gs to allow <strong>for</strong>local files be<strong>in</strong>g created.The SalesDataProvider helper class was designed to return the dynamically createdimage as an encoded text str<strong>in</strong>g packed <strong>in</strong> an <strong>XML</strong> document. This approach is notoptimal <strong>in</strong> a .<strong>NET</strong> Remot<strong>in</strong>g scenario, but it probably represents the only option if youhave to also publish the function through a Web service.435

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!