Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to verify the similarity of two QQ avatars with C #

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how C # verifies the similarity of two QQ avatars, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to verify the similarity of two QQ avatars. Let's take a look.

Use c # to find out the similarity between the avatar of some other qq and your own, and first look at the effect picture.

Here I use the avatar on the left as the basic picture of the comparison. What I am doing now is to compare one picture to one, because it is not difficult to understand one to one, one to many, and we can get similar pixels. Then the percentage greater than that is the change of the same picture. Here is the complete code.

Using Newtonsoft.Json;using Newtonsoft.Json.Linq;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.IO;using System.Linq;using System.Net;using System.Net.Http;using System.Text;using System.Threading.Tasks;using System.Windows.Forms Namespace WindowsFormsApp1 {public partial class Form1: Form {public Form1 () {InitializeComponent ();} public static int width; / / Picture width public static int height;// Picture High public static string mypicurl;// my picture address public static string picurl / / Image address private void Form1_Load (object sender, EventArgs e) {this.MyPicture.SizeMode = PictureBoxSizeMode.StretchImage; this.MyPicture.BorderStyle = BorderStyle.FixedSingle; this.OtherPicture.SizeMode = PictureBoxSizeMode.StretchImage; this.OtherPicture.BorderStyle = BorderStyle.FixedSingle This.explain.Text = "procedure: enter your own qq number to see the display on the left, enter someone else's qq number on the right, click to view, click to verify, and get the result." ;} private void button2_Click (object sender, EventArgs e) {Stopwatch stopwatch = new Stopwatch (); stopwatch.Start (); int countSame = 0; int countDifferent = 0; Image img = this.MyPicture.Image; Bitmap bitmapSource = new Bitmap (img); / / Bitmap bitmapSource = BytesToBitmap (ResizeImage (mypicurl)) Width = bitmapSource.Width; height = bitmapSource.Height; Bitmap bitmapTarget = BytesToBitmap (ResizeImage (picurl)); / / the photo size must be the same for (int I = 0; I

< bitmapTarget.Width; i++) { for (int j = 0; j < bitmapTarget.Height; j++) { if (bitmapSource.GetPixel(i, j).Equals(bitmapTarget.GetPixel(i, j))) { countSame++; } else { countDifferent++; } } } stopwatch.Stop(); this.result.Text = "相同像素个数:" + countSame + ",不同像素个数:" + countDifferent + "用时:" + stopwatch.ElapsedMilliseconds + " 毫秒"; } //byte[] 转图片 public static Bitmap BytesToBitmap(byte[] Bytes) { MemoryStream stream = null; try { stream = new MemoryStream(Bytes); return new Bitmap((Image)new Bitmap(stream)); } catch (ArgumentNullException ex) { throw ex; } catch (ArgumentException ex) { throw ex; } finally { stream.Close(); } } /// /// 图片大小裁剪 /// /// /// public static byte[] ResizeImage(string filePath) { WebRequest request = (WebRequest)HttpWebRequest.Create(filePath); WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { Bitmap bm = (Bitmap)Image.FromStream(stream); bm = GetThumbnail(bm, height, width); MemoryStream ms = new MemoryStream(); bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); byte[] bytes = ms.GetBuffer(); //byte[] bytes= ms.ToArray(); 这两句都可以,至于区别么,下面有解释 ms.Close(); return bytes; } } /// /// 修改图片的大小 /// /// /// /// /// public static Bitmap GetThumbnail(Bitmap b, int destHeight, int destWidth) { System.Drawing.Image imgSource = b; System.Drawing.Imaging.ImageFormat thisFormat = imgSource.RawFormat; int sW = 0, sH = 0; // 按比例缩放 int sWidth = imgSource.Width; int sHeight = imgSource.Height; if (sHeight >

DestHeight | | sWidth > destWidth) {if ((sWidth * destHeight) > (sHeight * destWidth)) {sW = destWidth; sH = (destWidth * sHeight) / sWidth;} else {sH = destHeight SW = (sWidth * destHeight) / sHeight;}} else {sW = sWidth; sH = sHeight;} Bitmap outBmp = new Bitmap (destWidth, destHeight); Graphics g = Graphics.FromImage (outBmp); g.Clear (Color.Transparent) / / set the drawing quality of the canvas g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage (imgSource, new Rectangle ((destWidth-sW) / 2, (destHeight-sH) / 2, sW, sH), 0,0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel); g.Dispose () / / when the following code saves the picture, set the compression quality EncoderParameters encoderParams = new EncoderParameters (); long [] quality = new long [1]; quality [0] = 100; EncoderParameter encoderParam = new EncoderParameter (System.Drawing.Imaging.Encoder.Quality, quality); encoderParams.Param [0] = encoderParam; imgSource.Dispose () Return outBmp;} private void button3_Click (object sender, EventArgs e) {if (this.OtherQQ.Text = = "") {MessageBox.Show ("Please enter qq number!") ; return;} HttpClient httpClient = new HttpClient (); string url = "https://api.usuuu.com/qq/" + this.OtherQQ.Text; var rsp = httpClient.GetAsync (url) .result; var str = rsp.Content.ReadAsStringAsync (). Result; JObject jo = (JObject) JsonConvert.DeserializeObject (str) If ((string) jo ["code"] = = "200") {Image pic = Image.FromStream (WebRequest.Create ((string) jo [" data "] [" avatar "]) .GetResponse () .GetResponseStream ()); this.OtherPicture.Image = pic; picurl = (string) jo [" data "] [" avatar "] } else {MessageBox.Show ("Please enter the correct qq number!") ;} private void button4_Click (object sender, EventArgs e) {if (this.MyQQ.Text = = "") {MessageBox.Show ("Please enter qq number!") ; return;} HttpClient httpClient = new HttpClient (); string url = "https://api.usuuu.com/qq/" + this.MyQQ.Text; var rsp = httpClient.GetAsync (url) .result; var str = rsp.Content.ReadAsStringAsync (). Result; JObject jo = (JObject) JsonConvert.DeserializeObject (str) If ((string) jo ["code"] = = "200") {Image pic = Image.FromStream (WebRequest.Create ((string) jo [" data "] [" avatar "]) .GetResponse () .GetResponseStream ()); this.MyPicture.Image = pic; mypicurl = (string) jo [" data "] [" avatar "] } else {MessageBox.Show ("Please enter the correct qq number!") This is the end of the article on "how to verify the similarity of two QQ avatars by C#". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to verify the similarity of two QQ avatars". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report