版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第C#驗證兩個QQ頭像相似度的示例代碼利用c#查看出某個其他qq的頭像與自己頭像的相似度,先看效果圖
這里我是將左邊的頭像作為比對的基本圖,我目前做的是一圖比對一圖,因為理解好了一對一,一對多也不難,我們可以得出相似的像素,然后大于多少百分比就是同一圖的改變了,以下是完整代碼
usingNewtonsoft.Json;
usingNewtonsoft.Json.Linq;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Diagnostics;
usingSystem.Drawing;
usingSystem.Drawing.Drawing2D;
usingSystem.Drawing.Imaging;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Net;
usingSystem.Net.Http;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
namespaceWindowsFormsApp1
publicpartialclassForm1:Form
publicForm1()
InitializeComponent();
publicstaticintwidth;//圖片寬
publicstaticintheight;//圖片高
publicstaticstringmypicurl;//我的圖片地址
publicstaticstringpicurl;//圖片地址
privatevoidForm1_Load(objectsender,EventArgse)
this.MyPicture.SizeMode=PictureBoxSizeMode.StretchImage;
this.MyPicture.BorderStyle=BorderStyle.FixedSingle;
this.OtherPicture.SizeMode=PictureBoxSizeMode.StretchImage;
this.OtherPicture.BorderStyle=BorderStyle.FixedSingle;
this.explain.Text="操作步驟:左邊輸入自己qq號查看顯示,右邊輸入別人qq號,點擊查看,點擊驗證,得出結(jié)果。";
privatevoidbutton2_Click(objectsender,EventArgse)
Stopwatchstopwatch=newStopwatch();
stopwatch.Start();
intcountSame=0;
intcountDifferent=0;
Imageimg=this.MyPicture.Image;
BitmapbitmapSource=newBitmap(img);
//BitmapbitmapSource=BytesToBitmap(ResizeImage(mypicurl));
width=bitmapSource.Width;
height=bitmapSource.Height;
BitmapbitmapTarget=BytesToBitmap(ResizeImage(picurl));
//照片尺寸必須一樣
for(inti=0;ibitmapTarget.Width;i++)
for(intj=0;jbitmapTarget.Height;j++)
if(bitmapSource.GetPixel(i,j).Equals(bitmapTarget.GetPixel(i,j)))
countSame++;
else
countDifferent++;
stopwatch.Stop();
this.result.Text="相同像素個數(shù):"+countSame+",不同像素個數(shù):"+countDifferent+"用時:"+stopwatch.ElapsedMilliseconds+"毫秒";
//byte[]轉(zhuǎn)圖片
publicstaticBitmapBytesToBitmap(byte[]Bytes)
MemoryStreamstream=null;
stream=newMemoryStream(Bytes);
returnnewBitmap((Image)newBitmap(stream));
catch(ArgumentNullExceptionex)
throwex;
catch(ArgumentExceptionex)
throwex;
finally
stream.Close();
///summary
///圖片大小裁剪
////summary
///paramname="filePath"/param
///returns/returns
publicstaticbyte[]ResizeImage(stringfilePath)
WebRequestrequest=(WebRequest)HttpWebRequest.Create(filePath);
WebResponseresponse=request.GetResponse();
using(Streamstream=response.GetResponseStream())
Bitmapbm=(Bitmap)Image.FromStream(stream);
bm=GetThumbnail(bm,height,width);
MemoryStreamms=newMemoryStream();
bm.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
byte[]bytes=ms.GetBuffer();//byte[]bytes=ms.ToArray();這兩句都可以,至于區(qū)別么,下面有解釋
ms.Close();
returnbytes;
///summary
///修改圖片的大小
////summary
///paramname="b"/param
///paramname="destHeight"/param
///paramname="destWidth"/param
///returns/returns
publicstaticBitmapGetThumbnail(Bitmapb,intdestHeight,intdestWidth)
System.Drawing.ImageimgSource=b;
System.Drawing.Imaging.ImageFormatthisFormat=imgSource.RawFormat;
intsW=0,sH=0;
//按比例縮放
intsWidth=imgSource.Width;
intsHeight=imgSource.Height;
if(sHeightdestHeight||sWidthdestWidth)
if((sWidth*destHeight)(sHeight*destWidth))
sW=destWidth;
sH=(destWidth*sHeight)/sWidth;
else
sH=destHeight;
sW=(sWidth*destHeight)/sHeight;
else
sW=sWidth;
sH=sHeight;
BitmapoutBmp=newBitmap(destWidth,destHeight);
Graphicsg=Graphics.FromImage(outBmp);
g.Clear(Color.Transparent);
//設(shè)置畫布的描繪質(zhì)量
g.CompositingQuality=CompositingQuality.HighQuality;
g.SmoothingMode=SmoothingMode.HighQuality;
g.InterpolationMode=InterpolationMode.HighQualityBicubic;
g.DrawImage(imgSource,newRectangle((destWidth-sW)/2,(destHeight-sH)/2,sW,sH),0,0,imgSource.Width,imgSource.Height,GraphicsUnit.Pixel);
g.Dispose();
//以下代碼為保存圖片時,設(shè)置壓縮質(zhì)量
EncoderParametersencoderParams=newEncoderParameters();
long[]quality=newlong[1];
quality[0]=100;
EncoderParameterencoderParam=newEncoderParameter(System.Drawing.Imaging.Encoder.Quality,quality);
encoderParams.Param[0]=encoderParam;
imgSource.Dispose();
returnoutBmp;
privatevoidbutton3_Click(objectsender,EventArgse)
if(this.OtherQQ.Text=="")
MessageBox.Show("請輸入qq號!");
return;
HttpClienthttpClient=newHttpClient();
stringurl="/qq/"+this.OtherQQ.Text;
varrsp=httpClient.GetAsync(url).Result;
varstr=rsp.Content.ReadAsStringAsync().Result;
JObjectjo=(JObject)JsonConvert.DeserializeObject(str);
if((string)jo["code"]=="200")
Imagepic=Image.FromStream(WebRequest.Create((string)jo["data"]["avatar"]).GetResponse().GetResponseStream());
this.OtherPicture.Image=pic;
picurl=(string)jo["data"]["avatar"];
else
MessageBox.Show("請輸入正確的qq號!");
privatevoidbutton4_Click(objectsender,EventArgse)
if(this.MyQQ.Text=="")
MessageBox.Show("請輸入qq號!");
return;
HttpClienthttpClient=newHttpClient();
stringurl="/qq/"+this.MyQQ.Text;
varrsp=httpClient.GetAsync(url).Result;
varstr=rsp.Content.ReadAsStringAsync().Result;
JObjectjo=(JObject)JsonConvert.Des
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026云南昆明高新技術(shù)產(chǎn)業(yè)開發(fā)區(qū)管理委員會招聘18人備考題庫附答案
- 2026農(nóng)業(yè)農(nóng)村部國際交流中心面向社會招聘編制外人員招聘2人備考題庫附答案詳解(能力提升)
- 2026安徽馬鞍山當(dāng)涂法院招聘1人備考題庫附參考答案詳解(達標(biāo)題)
- 2026廣東東莞市石碣鎮(zhèn)招聘編外聘用人員5人備考題庫帶答案詳解(培優(yōu))
- 2026福建漳州市詔安縣機關(guān)事業(yè)單位社會保險中心招募見習(xí)人員2人備考題庫及答案詳解(奪冠系列)
- 2026陜西西安市高陵區(qū)殘疾人專職委員選聘3人備考題庫帶答案詳解
- 2026黑龍江二龍濤濕地省級自然保護區(qū)管護中心公益性崗位招聘5人備考題庫及參考答案詳解1套
- 2026河南周口鹿邑縣德源中學(xué)招聘備考題庫及1套完整答案詳解
- 2026聊城陽谷法院勞務(wù)派遣招聘備考題庫及1套參考答案詳解
- 2026福建省融資擔(dān)保有限責(zé)任公司社會招聘3人備考題庫及1套完整答案詳解
- 水產(chǎn)養(yǎng)殖技術(shù)手冊
- 英國汽車工業(yè)市場分析現(xiàn)狀供需格局投資前景未來規(guī)劃研究報告
- 2025年及未來5年市場數(shù)據(jù)中國吸塑、注塑行業(yè)發(fā)展前景預(yù)測及投資戰(zhàn)略數(shù)據(jù)分析研究報告
- 眼科醫(yī)療風(fēng)險防范培訓(xùn)
- 物流金融理論與實務(wù)課件
- 海內(nèi)外云廠商發(fā)展與現(xiàn)狀(三):資本開支壓力與海外云廠需求情況拆解-國信證券
- 2025年社區(qū)網(wǎng)格員招錄考試真題庫(含答案)
- GB/T 46510-2025玩具水基材料中游離甲醛的測定高效液相色譜法
- 溴化鋰清洗施工方案
- 第四方支付業(yè)務(wù)合規(guī)指引
- 手勢舞基本功課件
評論
0/150
提交評論