Save as Image on the iPhone

126 views Asked by At

I have a website which is visited mainly from iPhone. On my pages the users have the chance to get discount coupons. I need to implement a feature which the user can use to save the coupon image on his device.

I have created a controller which return a File to the client but unfortunately the browser just shows the image because it knows the content type which is image/png

Is there any way to make the iPhone save the image directly?

This is my controller action code

[AllowAnonymous]
public ActionResult SaveAsImage( string code, int campaign ) {
    string theUrl = string.Format( Constants.DEFAULT_CONSUME_URL, code, campaign );
    var barcodeWriter = new BarcodeWriter() {
        Format = BarcodeFormat.QR_CODE,
        Options = new EncodingOptions {
            Height = 250,
            Width = 250,
            Margin = 0
        }
    };
    using ( var bitmap = barcodeWriter.Write( theUrl ) ) {
        using ( var stream = new MemoryStream() ) {
            bitmap.Save( stream, ImageFormat.Png );
            var cd = new System.Net.Mime.ContentDisposition {
                // for example foo.bak
                FileName = "coupon.png",
                // always prompt the user for downloading, set to true if you want 
                // the browser to try to show the file inline
                Inline = false,
            };
            Response.AppendHeader( "Content-Disposition", cd.ToString() );
            return File( stream.ToArray(), "image/png" );
        }
    }
}
1

There are 1 answers

0
rckoenes On BEST ANSWER

Short answer, NO.

You will have to instruct the user to save the image. But you can use a Passbook file, which your server can create, to allow the user to save the coupon.

You can read more about Passbook here:Passbook Programming Guide Apples simple Passbook example: Building Your First Pass