Home > Net >  Qr code how to turn the inside of the black spots to dot
Qr code how to turn the inside of the black spots to dot

Time:03-19

I use QRCodeEncoder QRCodeEncoder=new QRCodeEncoder ();
QrCodeEncoder. QRCodeScale=4;
QrCodeEncoder. QRCodeErrorCorrect=qrCodeEncoder. ERROR_CORRECTION. M;

Bitmap bt=qrCodeEncoder. Encode (STR, Encoding. The Default);
Bt. Save (QRurl, ImageFormat. Png);
Qr code is generated after

How to make the black point inside the following dot


Or, how can directly generate dot the qr code, I use the ZXing. DLL and ThoughtWorks QRCode. Codec. The DLL is not dot,

Have drawn a great god explain? The new study

CodePudding user response:

 using System; 
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;

The namespace QRCodeTransfer
{
Public partial class Form1: Form
{
Private Bitmap raw_image=(Bitmap) Image. FromFile (" raw_code. PNG ");
Private Bitmap target_image=null;
Public _click ()
{
InitializeComponent ();
}

Protected override void onl oad (EventArgs e)
{
Base. The onl oad (e);
}

Private void panel1_Paint (object sender, PaintEventArgs e)
{
Um participant raphics. DrawImage (raw_image, 0, 0, panel1. Width, panel1. Height);
}

Private void panel2_Paint (object sender, PaintEventArgs e)
{
If (target_image!=null)
{
Um participant raphics. DrawImage (target_image, 0, 0, panel2. Width, panel2. Height);
}
}

Private void button1_Click (object sender, EventArgs e)
{
//1. The calculated minimum width
Target_image=new Bitmap (raw_image. Width, raw_image. Height);
Int x=raw_image. Width/2;
A Rectangle center_box=new Rectangle ();
Color center_color=raw_image. GetPixel (x, x);
Int box_left=0;
Int box_right=0;
While (x> 0)
{
If (raw_image. GetPixel (x, x)!=center_color)
{
Box_left=x + 1;
break;
}
X -;
}
X=raw_image. Width/2;
While (x & lt; Raw_image. Width)
{
If (raw_image. GetPixel (x, x)!=center_color)
{
Box_right=x - 1;
break;
}
X++;
}
Int a=box_right box_left + 1;
Center_box=new Rectangle (box_left box_left, a, a);

//2. Draw the new qr code
Using (Graphics g=Graphics. FromImage (target_image))
{
Right to Lear (Color. White);
Int box_count=raw_image. Width/center_box. Width;
for (int i=0; I & lt; Box_count; I++)
{
For (int j=0; J & lt; Box_count; J++)
{
If (raw_image GetPixel (I * center_box in Width, j * center_box Height)==center_color)
{
A Rectangle box=new Rectangle (I * center_box in Width, j * center_box Height, center_box. Width, center_box. Height);
G.F illEllipse (Brushes. Black box);
}
}
}
}
Target_image. Save (" target. PNG, "System. Drawing. Imaging. ImageFormat. PNG);

//3. Update interface
Panel2. Invalidate ();
}
}
}
  • Related