7 people like it.
Like the snippet!
Making QR-code image having contact information (VCard) with Google Chart API
Making QR-code image having contact information (VCard) with Google Chart API.
If you scan this image with mobile phone, you can directly add new person to your contacts.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
|
open System
open System.IO
open System.Net
open System.Drawing
let ImageSize = 300
let fetchImage (url : Uri) =
let req = WebRequest.Create (url) :?> HttpWebRequest
use stream = req.GetResponse().GetResponseStream()
Image.FromStream(stream)
let googleChartQRCodeImage mydata =
let addr = String.Format("http://chart.apis.google.com/chart?chs={0}x{0}&cht=qr&chl={1}&choe=ISO-8859-1", ImageSize, mydata)
new Uri(addr, UriKind.Absolute)
let vcard = @"BEGIN:VCARD
VERSION:3.0
N:{1};{0};
FN:{0} {1}
NICKNAME:{2}
ORG:{3}
ROLE:{4}
TITLE:{4}
PHOTO;MEDIATYPE={6}:{5}
TEL;TYPE=CELL:{7}
X-TWITTER:{8}
URL:{9}
EMAIL;TYPE=PREF,INTERNET:{10}
ADR;TYPE=HOME:;;{11};{12};;{13};{14}
LABEL;TYPE=HOME:{11}\n{13} {12}\n{14}
REV:{15}
END:VCARD
"
let googleChartUri contact =
String.Format(vcard, contact)
|> Uri.EscapeDataString
|> googleChartQRCodeImage
let sample : obj [] = [|
"Matt"; //first name
"Oneofus"; //surname
"matias"; //nickname
"Company & co."; //organization
"Guru"; //title
"http://www.wpclipart.com/signs_symbol/icons_oversized/male_user_icon.png"; //image url
"image/png"; //picture mime-type, eg. image/gif or image/jpeg
"+358 50 123 4567"; //cell phone
"Thoriumi"; // twitter account
"http://www.iki.fi/thorium/"; // url
"nospam@mailinator.com"; //email
"Katuroad 1 A 5"; // street address
"Espoo"; //city
"02100"; //postal code
"Finland"; //country
System.DateTime.Now.ToString("yyyyMMddThhmmssZ"); // timestamp
|]
open System.Windows.Forms
let showImage =
let form = new Form()
let pb = new PictureBox()
pb.Image <- sample |> googleChartUri |> fetchImage
pb.SizeMode <- PictureBoxSizeMode.AutoSize
form.Height <- ImageSize+50
form.Width <- ImageSize+50
form.Controls.Add(pb)
form.Show()
|
namespace System
namespace System.IO
namespace System.Net
namespace System.Drawing
val ImageSize : int
val fetchImage : url:Uri -> 'a
val url : Uri
Multiple items
type Uri =
interface ISerializable
new : uriString: string -> unit + 7 overloads
member AllowIdnStatic : syntax: UriParser * flags: Flags -> bool
member Canonicalize : unit -> unit
member CheckAuthorityHelper : pString: nativeptr<char> * idx: uint16 * length: uint16 * err: byref<ParsingError> * flags: byref<Flags> * syntax: UriParser * newHost: byref<string> -> uint16
member CheckAuthorityHelperHandleAnyHostIri : pString: nativeptr<char> * startInput: int * end: int * iriParsing: bool * hasUnicode: bool * syntax: UriParser * flags: byref<Flags> * newHost: byref<string> * err: byref<ParsingError> -> unit
member CheckAuthorityHelperHandleDnsIri : pString: nativeptr<char> * start: uint16 * end: int * startInput: int * iriParsing: bool * hasUnicode: bool * syntax: UriParser * userInfoString: string * flags: byref<Flags> * justNormalized: byref<bool> * newHost: byref<string> * err: byref<ParsingError> -> unit
member CheckCanonical : str: nativeptr<char> * idx: byref<uint16> * end: uint16 * delim: char -> Check
member CheckForEscapedUnreserved : data: string -> bool
member CheckForUnicode : data: string -> bool
...
--------------------
Uri(uriString: string) : Uri
Uri(uriString: string, uriKind: UriKind) : Uri
Uri(baseUri: Uri, relativeUri: string) : Uri
Uri(baseUri: Uri, relativeUri: Uri) : Uri
val req : HttpWebRequest
type WebRequest =
inherit MarshalByRefObject
interface ISerializable
new : unit -> unit + 1 overload
member <GetRequestStreamAsync>b__67_0 : unit -> Task<Stream>
member <GetResponseAsync>b__68_0 : unit -> Task<WebResponse>
member Abort : unit -> unit
member BeginGetRequestStream : callback: AsyncCallback * state: obj -> IAsyncResult
member BeginGetResponse : callback: AsyncCallback * state: obj -> IAsyncResult
member EndGetRequestStream : asyncResult: IAsyncResult -> Stream
member EndGetResponse : asyncResult: IAsyncResult -> WebResponse
...
WebRequest.Create(requestUri: Uri) : WebRequest
WebRequest.Create(requestUriString: string) : WebRequest
Multiple items
type HttpWebRequest =
inherit WebRequest
interface ISerializable
new : unit -> unit + 2 overloads
member Abort : unit -> unit
member AddRange : from: int * to: int -> unit + 8 overloads
member BeginGetRequestStream : callback: AsyncCallback * state: obj -> IAsyncResult
member BeginGetResponse : callback: AsyncCallback * state: obj -> IAsyncResult
member CheckAbort : unit -> unit
member EndGetRequestStream : asyncResult: IAsyncResult * context: byref<TransportContext> -> Stream + 1 overload
member EndGetResponse : asyncResult: IAsyncResult -> WebResponse
...
--------------------
HttpWebRequest() : HttpWebRequest
val stream : Stream
HttpWebRequest.GetResponse() : WebResponse
val googleChartQRCodeImage : mydata:'a -> Uri
val mydata : 'a
val addr : string
Multiple items
type String =
interface IComparable
interface IEnumerable
interface IConvertible
interface IEnumerable<char>
interface IComparable<string>
interface IEquatable<string>
interface ICloneable
new : value: char [] -> unit + 8 overloads
member Clone : unit -> obj
member CompareTo : value: obj -> int + 1 overload
...
--------------------
String(value: char []) : String
String(value: nativeptr<char>) : String
String(value: nativeptr<sbyte>) : String
String(value: ReadOnlySpan<char>) : String
String(c: char, count: int) : String
String(value: char [], startIndex: int, length: int) : String
String(value: nativeptr<char>, startIndex: int, length: int) : String
String(value: nativeptr<sbyte>, startIndex: int, length: int) : String
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : String
String.Format(format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj) : string
String.Format(provider: IFormatProvider, format: string, [<ParamArray>] args: obj []) : string
String.Format(provider: IFormatProvider, format: string, arg0: obj) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(provider: IFormatProvider, format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
String.Format(provider: IFormatProvider, format: string, arg0: obj, arg1: obj, arg2: obj) : string
type UriKind =
| RelativeOrAbsolute = 0
| Absolute = 1
| Relative = 2
field UriKind.Absolute: UriKind = 1
val vcard : string
val googleChartUri : contact:obj [] -> Uri
val contact : obj []
Uri.EscapeDataString(stringToEscape: string) : string
val sample : obj []
type obj = Object
Multiple items
[<Struct>]
type DateTime =
new : ticks: int64 -> unit + 13 overloads
member Add : value: TimeSpan -> DateTime + 1 overload
member AddDays : value: float -> DateTime
member AddHours : value: float -> DateTime
member AddMilliseconds : value: float -> DateTime
member AddMinutes : value: float -> DateTime
member AddMonths : months: int -> DateTime
member AddSeconds : value: float -> DateTime
member AddTicks : value: int64 -> DateTime
member AddYears : value: int -> DateTime
...
--------------------
DateTime ()
(+0 other overloads)
DateTime(ticks: int64) : DateTime
(+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
(+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
(+0 other overloads)
property DateTime.Now: DateTime with get
DateTime.ToString() : string
DateTime.ToString(provider: IFormatProvider) : string
DateTime.ToString(format: string) : string
DateTime.ToString(format: string, provider: IFormatProvider) : string
namespace System.Windows
val showImage : obj
val form : obj
val pb : obj
More information