GVKun编程网logo

求你两个源码。。获取QQ头像,QQ名,还有JSON调试(获取qq头像代码)

11

这篇文章主要围绕求你两个源码。。获取QQ头像,QQ名,还有JSON调试和获取qq头像代码展开,旨在为您提供一份详细的参考资料。我们将全面介绍求你两个源码。。获取QQ头像,QQ名,还有JSON调试的优缺

这篇文章主要围绕求你两个源码。。获取QQ头像,QQ名,还有JSON调试获取qq头像代码展开,旨在为您提供一份详细的参考资料。我们将全面介绍求你两个源码。。获取QQ头像,QQ名,还有JSON调试的优缺点,解答获取qq头像代码的相关问题,同时也会为您带来C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的方法、C#验证两个QQ头像相似度的示例代码、Discuz!使用QQ登录注册后如何默认取消使用QQ头像和QQ秀、GDI+_绘制QQ头像的实用方法。

本文目录一览:

求你两个源码。。获取QQ头像,QQ名,还有JSON调试(获取qq头像代码)

求你两个源码。。获取QQ头像,QQ名,还有JSON调试(获取qq头像代码)

@helong 你好,想跟你请教个问题:


http://doido.sinaapp.com/json/  这个的

http://doido.sinaapp.com/qqpic/?qq=200708691

http://doido.sinaapp.com/qqname/?qq=200708691

对这三个源码很感兴趣啊。。


C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的方法

C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的方法

效果图:

在这里插入图片描述

完全代码(下方有详细解读)

 private void textBox1_TextChanged(object sender, EventArgs e)
        {//这里是文本框的事件 值发生 改变时发生

            StringBuilder UserID = new StringBuilder(20);
            //值经常发生改变 使用StringBuilder 并且开辟20字符的空间

            Regex r = new Regex(@"[\d]");
            //正则表达式 过滤字符  \d表示只要0-9的数字
            //也就是全部数字

            MatchCollection match = r.Matches(textBox1.Text);
            //需要匹配的字符串 

            foreach (Match user in match)
            {//使用循环 过滤不需要的字符串

                UserID.Append(user);
                //过滤好的字符串 添加进StringBuilder
            }

            if (UserID.Length <= 4)
            {
                //判断匹配好的字符串是否大于4
                //因为QQ最低是5位数...
                return;
            }


            Thread th = new Thread(() => beg(UserID.ToString()));
            //创建线程      把 StringBuilder 值传递过去

            th.IsBackground = true;
            //设置成后台线程

            th.Start();
            //开始线程
        }

线程执行的方法:

 public void beg(string id)
        {
            //线程执行的方法体


           try
            {
                HttpWebRequest beg = (HttpWebRequest)WebRequest.Create("http://q1.qlogo.cn/g?b=qq&nk="+id+"&s=2");
                //发送请求 

                beg.Timeout = 5000;
                //请求的时间为5秒 超过就停止请求

                HttpWebResponse wb = (HttpWebResponse)beg.GetResponse();
                //接收服务器返回的请求

                Stream s = wb.GetResponseStream();
                //把回来的请求变 一个 流

                using (Image i = new Bitmap(s))
                {    //把流传递过来

                    Bitmap b = new Bitmap(50, 50); //初始像素值

                    using (Graphics g = Graphics.FromImage(b))
                    {//使用Gdi画图  在图片上画 

                        g.SmoothingMode = SmoothingMode.HighQuality;
                        //图片的抗锯齿

                        using (GraphicsPath p = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate))
                        {
                            p.AddEllipse(0, 0, i.Width, i.Height);//添加椭圆

                            g.FillPath(new TextureBrush(i), p);//填充里面

                            pictureBox1.Image = b;
                            //赋值给图片框
                        }

                    }

                }
            }
            catch
            {

            }

        }

前言:

某论坛的评论区模块,发现这功能很不错,琢磨了一晚上做了大致一样的,用来当做 注册模块 的头像绑定功能

某论坛评论区模块(动图)

在这里插入图片描述

注册模块功能建议:

用户注册时,可以选择性的上传头像,如果没上传头像,就默认使用QQ绑定的头像

获取QQ头像的接口:

http://q1.qlogo.cn/g?b=qq&nk=这里是QQ号&s=2 这里是尺寸

http://q1.qlogo.cn/g?b=qq&nk=972001531&s=2

尺寸标识符 尺寸大小
1 40 × 40
2 40 × 40
3 100 × 100
4 140 × 140
5 640 × 640
40 40 × 40
100 100 × 100
按照自己头像框的大小自行选择

就是一个头像的URl

请添加图片描述

也可以可下载本地 上传服务器等…自行研究

接口有了 接下来就是 使用C#去实现功能了…

界面图:

为了方便演示 没有做其他的功能…简单的搭建了一个窗体

在这里插入图片描述
在这里插入图片描述

从图可以看出 每修改一个数字都会重新获取一次的头像,
所以代码就写在文本框的事件里

请添加图片描述

该事件的意思就是 每当文本框的内容发生改变时发生

过滤输入的字符:

请添加图片描述

考虑到可能会输入一些 乱七八糟的字符串
例:9720ada15
这样就识别不了是一个QQ号 所以需要过滤掉,只识别数字

正则表达式过滤字符:
定义规则

 Regex r = new Regex(@"[\d]");
//正则表达式 过滤字符  \d表示只要0-9的数字
   或者
 Regex r = new Regex(@"[0-9]");         

存储匹配好的字符串

 Regex r = new Regex(@"[\d]");
//正则表达式 过滤字符  \d表示只要0-9的数字
   或者
 Regex r = new Regex(@"[0-9]");         

匹配字符串:

 foreach (Match user in match)
            {//使用循环 过滤不需要的字符串

                UserID.Append(user);
                //过滤好的字符串 添加进StringBuilder
            }

判断匹配好的长度

 if (UserID.Length <= 4)
            {
                //判断匹配好的字符串是否大于4
                //因为QQ最低是5位数...
                return;
                //不大于4就返回
            }

使用接口QQ接口:

因为接口是一个网页 所以需要发送请求
需要用到

HttpWebRequest: 发送网页请求
HttpWebResponse: 接收服务器发送的请求

在这里插入图片描述

但发送请求时又有一个 问题 那就是 如果网速比较慢 或者 服务器 响应速度慢 会造成 软件的假死 但是可以通过线程解决这个问题…

定义线程:

Thread th = new Thread(() => beg(UserID.ToString()));
    //创建线程      把 StringBuilder 值传递过去
    
    th.IsBackground = true;
    //设置成后台线程

    th.Start();
    //开始线程
}

线程执行的方法:

发起请求:

 HttpWebRequest beg = (HttpWebRequest)WebRequest.Create("http://q1.qlogo.cn/g?b=qq&nk="+id+"&s=2");
                //发送请求 
 beg.Timeout = 5000;
                //请求的时间为5秒 超过就停止请求

接收返回请求:

   HttpWebResponse wb = (HttpWebResponse)beg.GetResponse();
        //接收服务器返回的请求 流的方式

使用流转换:

得到流后 可以把图片保存到 本地 等等…

  Stream s = wb.GetResponseStream();
                //把回来的请求变 一个 流

图片转成圆形:

图片框的默认情况下是 方形

在这里插入图片描述

并没有直接的属性变成圆形…
这里使用GDI继续绘制

using (Image i = new Bitmap(s))
                {    //把流传递过来

                    Bitmap b = new Bitmap(50, 50); //初始像素值

                    using (Graphics g = Graphics.FromImage(b))
                    {//使用Gdi画图  在图片上画 

                        g.SmoothingMode = SmoothingMode.HighQuality;
                        //图片的抗锯齿

                        using (GraphicsPath p = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate))
                        {
                            p.AddEllipse(0, 0, i.Width, i.Height);//添加椭圆

                            g.FillPath(new TextureBrush(i), p);//填充里面

                            pictureBox1.Image = b;
                            //赋值给图片框
                        }

                    }

                }

在这里插入图片描述

这样就完成了 …

到此这篇关于C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的文章就介绍到这了,更多相关C# 圆形头像框内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

您可能感兴趣的文章:
  • C#利用GDI+绘制旋转文字等效果实例
  • C# 使用GDI绘制雷达图的实例
  • C#利用GDI绘制常见图形和文字
  • C#使用GDI绘制矩形的方法
  • C#使用GDI绘制直线的方法
  • 深入C# winform清除由GDI绘制出来的所有线条或图形的解决方法
  • C#中GDI+绘制圆弧及圆角矩形等比缩放的绘制

C#验证两个QQ头像相似度的示例代码

C#验证两个QQ头像相似度的示例代码

利用c#查看出某个其他qq的头像与自己头像的相似度,先看效果图

请添加图片描述

这里我是将左边的头像作为比对的基本图,我目前做的是一图比对一图,因为理解好了一对一,一对多也不难,我们可以得出相似的像素,然后大于多少百分比就是同一图的改变了,以下是完整代码

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; //图片宽
        public static int height;//图片高
        public static string mypicurl;//我的图片地址
        public static string picurl;//图片地址
        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 = "操作步骤:左边输入自己qq号查看显示,右边输入别人qq号,点击查看,点击验证,得出结果。";
        }

        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));
            //照片尺寸必须一样
            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();
            }
        }
        /// <summary>
        /// 图片大小裁剪
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        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;
            }

        }
        /// <summary>
        /// 修改图片的大小
        /// </summary>
        /// <param name="b"></param>
        /// <param name="destHeight"></param>
        /// <param name="destWidth"></param>
        /// <returns></returns>
        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);
            // 设置画布的描绘质量         
            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();
            // 以下代码为保存图片时,设置压缩质量     
            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("请输入qq号!");
                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("请输入正确的qq号!");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (this.MyQQ.Text == "")
            {
                MessageBox.Show("请输入qq号!");
                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("请输入正确的qq号!");
            }
        }
    }
}

到此这篇关于c#验证两个QQ头像相似度的文章就介绍到这了,更多相关c#QQ头像相似度内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

您可能感兴趣的文章:
  • C#计算2个字符串的相似度
  • C#实现的字符串相似度对比类
  • C#开发的人脸左右相似度计算软件源码分析
  • C#和SQL实现的字符串相似度计算代码分享

Discuz!使用QQ登录注册后如何默认取消使用QQ头像和QQ秀

Discuz!使用QQ登录注册后如何默认取消使用QQ头像和QQ秀

  discuz!在开启QQ互联后,用户使用QQ互联进行登录时会提示勾选使用QQ头像和QQ秀。   但是该功能经常无法获取到头像或者QQ秀,即使使用QQ秀也会因为QQ秀太长或者没有装扮影响网站效果。 而QQ秀的取消绑定又相对隐蔽,因此最好的办法就是在默认不勾选使用QQ头像和QQ秀。   最新版QQ互联程序,编辑source\plugin\qqconnect\template\module.htm 大约在486行找到 <label  for=use_qzone_avatar_qqshow><input type=checkBox name=use_qzone_avatar_qqshow id=use_qzone_avatar_qqshow class=pc value=1 checked=checked tabindex=1 />{lang qqconnect:connect_register_use_qzone_avatar_qqshow}</label>   其中删除 checked=checked   保存并登录论坛后台更新缓存 默认就不勾选了

GDI+_绘制QQ头像

GDI+_绘制QQ头像

Public Sub I_touxiang(ByVal file As String, ByVal Graphics As Long, Width As Long, Height As Long, Optional SavePath As String)
''做这个是因为昨天晚上雅铭居士的论坛登录器的有需要。一个利用GDI +制作的QQ头像效果
''By 2019.2.16 22:00 InkHin
Dim Bitmap As Long, bmW As Long, bmH As Long
Dim Brush As Long
Dim Path As Long
Dim newImg As Long, newGraphics As Long

Call GdipCreateBitmapFromFile(StrPtr(file), Bitmap)  ''获取Bitmap
Call GdipGetImageWidth(Bitmap, bmW)  ''得到Bitmap的尺寸
Call GdipGetImageHeight(Bitmap, bmH)
Call GdipCreateTexture2I(Bitmap, WrapModeTile, 0, 0, bmW, bmH, Brush) ''
Call GdipCreateBitmapFromScan0(bmW, bmH, 0, PixelFormat32bppARGB, ByVal 0, newImg) ''
Call GdipGetImageGraphicsContext(newImg, newGraphics) ''
Call GdipGraphicsClear(newGraphics, &HFFFFFF) ''
Call GdipSetSmoothingMode(Graphics, SmoothingModeAntiAlias)  ''反锯齿
Call GdipCreatePath(FillModeAlternate, Path) ''
Call GdipAddPathArcI(Path, 0, 0, bmW, bmH, 0, 360) ''
Call GdipFillPath(newGraphics, Brush, Path) ''
Call GdipDrawImageRectI(Graphics, newImg, 0, 0, Width, Height)
If Not IsMissing(SavePath) Then
If SaveImageToPNG(newImg, SavePath) <> 0 Then MsgBox "保存失败。"
End If
''一堆删除 Call GdipDeleteGraphics(Graphics) Call GdipDisposeImage(Bitmap) Call GdipDeleteGraphics(newGraphics) Call GdipDisposeImage(newImg) Call GdipDeletePath(Path) Call GdipDeleteBrush(Brush) End Sub

 

今天关于求你两个源码。。获取QQ头像,QQ名,还有JSON调试获取qq头像代码的介绍到此结束,谢谢您的阅读,有关C# 获取指定QQ头像绘制圆形头像框GDI(Graphics)的方法、C#验证两个QQ头像相似度的示例代码、Discuz!使用QQ登录注册后如何默认取消使用QQ头像和QQ秀、GDI+_绘制QQ头像等更多相关知识的信息可以在本站进行查询。

本文标签: