Server-side image creation in ASP.NET Mobile Web Application

R

RicardoVeloso

Hi,

I have to generate an image based on information saved in a DB.
This image needs to contain the draw of a cinema room places. This work has
the objective to implement a Online cinema ticket reservation.

I try this:
Bitmap bitmap = new Bitmap(10,10);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

g.DrawLine(new Pen(Color.BurlyWood), 0, 0, 10, 10);

bitmap.Save("image1.png", System.Drawing.Imaging.ImageFormat.Png);
Image1.ImageUrl = Server.MapPath(Session.SessionID + ".png");

But the Save method is not available in .NETCF, and I don't know if this is
the best way to force an image to be visible on the client-side.

Any help to turn around this problem?

Thanx a lot,
Ricardo Veloso
 
T

Ted Harper

I try this:
Bitmap bitmap = new Bitmap(10,10);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

g.DrawLine(new Pen(Color.BurlyWood), 0, 0, 10, 10);

bitmap.Save("image1.png", System.Drawing.Imaging.ImageFormat.Png);
Image1.ImageUrl = Server.MapPath(Session.SessionID + ".png");

But the Save method is not available in .NETCF, and I don't know if this is
the best way to force an image to be visible on the client-side.

If you are creating the image on the server side as your post says,
then you shouldn't be worred about what the Compact Framework does or
doesn't support, since the image-generation code is NOT running on the
handheld device. In your web server code (running under the full .Net
Framework) you will be doing more-or-less the same to target a mobile
browser as a "full featured" desktop PC browser.

That is, on the web server you will have a SomeDynamicImage.aspx page
which actually returns a GIF or JPEG image, and you will reference
that inside a mobile image control as something like:

<mobile:Image ID="imgRiskChart" Runat="server"
ImageUrl="SomeDynamicImage.aspx"></mobile:Image>

There are a few things to be careful of when writing this dynamic
image to support mobile devices (and I am assuming you already have
the equivalent dynamic image creation working for full desktop
browsers - if not I highly recommend you do this first, just for ease
of debugging your overall chart creation code):

* You should extend System.Web.UI.Page (rather than MobilePage) for
your dynamic image ASPX, to avoid it being attempted to be processed
by the ASP.Net Mobile framework (which doesn't understand a page
having an image MIME type).

* Your calling page (ie the page with the mobile:image tag referencing
the dynamic image) will need to pass in the image size (X/Y
dimenstions), colour depth, preferred MIME type for output image (eg
GIF, JPG, WBMP), and do this dynamically in the codebehind for each
request, because all handheld devices are different.

* When building/updating the ImageUrl in the mobile:Image control,
you'll also have to manually append the authentication cookie if you
are using forms authentication and cookieless (as you'll probably have
to for good wide mobile device support), since this won't be affixed
to the ImageURL automatically by the framework (and if you don't, the
framework will redirect the image content to the logon page, rather
than your rendering code getting run).

Aside from that stuff, you _should_ be able to get your existing
(non-Mobile) ASP.Net dynamic chart/image code working for mobile
clients pretty quickly.

Hope this helps,
ted.h.
 

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top