[討論] google api qrcode轉存圖片<研究出來了..>
各位好...
最近才開始學習寫C#
還請各位幫忙給我一點建議,謝謝了
目前是寫一個WEB FORM 用C#
=====================================================================
然後碰到的問題是:
我利用了GOOGLE API 產生出來的QRCODE,該怎麼樣能夠轉存到我的資料夾裡呢?
<註解後面的是參考GOOGLE出來的資料自己的測試...>
再麻煩各位大大
辛苦各位了
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Net;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// 設定 Google Chart API 的網址參數
string strQRcode =
"http://chart.apis.google.com/chart?cht=qr&chs=150x150&chld=M&chl=" +
this.TextBox1.Text;
// 讀取網路圖片到 image
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strQRcode);
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
if (rsp.StatusCode == System.Net.HttpStatusCode.OK)
{
this.Image1.ImageUrl = strQRcode;
================================以下為參考後的個人測試======================
// 測試抓取 Google Logo.
Uri uri = new Uri(strQRcode);
string saveDir =
@"D:\ASPNET\WebApplication1\WebApplication1\NewFolder1\"; // 注意:資料夾必須
已存在
string fileName = "google.png";
string savePath = saveDir + fileName;
System.Net.WebRequest request =
System.Net.WebRequest.Create(uri);
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
Image img = Image.FromStream(stream);
img.Save(savePath);
////image1.Saveas(Server.MapPath(@"~\NewFloder1\"+
TextBox2.Text));
////Image1.ImageUrl.ToString();
////Image1.ImageUrl.GetTypeCode.SaveAs(Server.MapPath(@"~\PhotoDate\" +
FileUpload1.FileName))
//System.Net.WebClient WC = new System.Net.WebClient();
//System.IO.MemoryStream Ms = new
System.IO.MemoryStream(WC.DownloadData(strQRcode));
//Image1 img = image.FromStream(Ms);
//img.Saveas(Server.MapPath(@"~\NewFloder1\"+
TextBox2.Text));
}
============================================================================
rsp.Close();
辛苦各位了...感激!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.231.183
→
07/29 22:04, , 1F
07/29 22:04, 1F
我正在努力GOOGLE...XD希望樓上也能幫個忙@@"
編譯的話~~~是指執行嗎?
我拉的物件只有三個 Textbox button image
這篇還缺}}
※ 編輯: linxintw 來自: 61.230.224.161 (07/30 00:06)
===========================個人測試完成的解答==============================
經過一個晚上的努力(功力太弱...)
終於完成了製造圖片&把圖片下載存檔的方法
就在這裡分享給大家
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Net;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// 設定 Google Chart API 的網址參數
string strQRcode =
"http://chart.apis.google.com/chart?cht=qr&chs=150x150&chld=M&chl=" +
this.TextBox1.Text + this.TextBox2.Text;
// 讀取網路圖片到 image
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strQRcode);
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
if (rsp.StatusCode == System.Net.HttpStatusCode.OK)
{
this.Image1.ImageUrl = strQRcode;
string url = strQRcode;
string filepath =
Server.MapPath(@"~\NewFolder1\"+TextBox2.Text+".jpg");
WebClient mywebclient = new WebClient();
mywebclient.DownloadFile(url, filepath);
}
rsp.Close();
}
}
}
※ 編輯: linxintw 來自: 61.230.224.161 (07/30 01:10)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章