QR코드 이미지 코드 생성 + 이미지 워터마크 추가 + 내보내기
8018 단어 QR코드
1. QR코드 생성
ZXing은 자바로 구현된 다양한 형식의 1D/2D 바코드 이미지 처리 라이브러리로 다른 언어와 연결된 포트를 포함한다.Zxing은 휴대전화에 내장된 카메라를 이용해 바코드 스캔 및 디코딩을 완료할 수 있다.이 프로젝트에서 실현할 수 있는 바코드 인코딩과 디코딩QR 인코딩, Data Matrix, UPC의 1D 바코드를 디코딩하는 것이 목표입니다.J2ME, J2SE, Android 등 다양한 플랫폼의 클라이언트를 제공합니다.QRcode를 디코딩하는 데 사용됩니다.본문은 zxing을 인용한다.dll, QR코드를 생성합니다.
참조 네임스페이스:
using com.google.zxing.qrcode;
using com.google.zxing;
using com.google.zxing.common;
using ByteMatrix = com.google.zxing.common.ByteMatrix;
using EAN13Writer = com.google.zxing.oned.EAN13Writer;
using EAN8Writer = com.google.zxing.oned.EAN8Writer;
using MultiFormatWriter = com.google.zxing.MultiFormatWriter;
using System.IO;
using System.Collections;
QR코드를 생성하려면 다음과 같이 하십시오.
private void btnGenerate_Click(object sender, EventArgs e)
{
ByteMatrix byteMatrix;
string content = this.textBox1.Text;
if (!string.IsNullOrEmpty(content))
{
byteMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 300, 300);
bitmap = ToBitmap(byteMatrix);
}
this.pictureBox1.Image = bitmap;
mapCreate = bitmap;
}
public static Bitmap ToBitmap(ByteMatrix matrix)
{
int width = matrix.Width;
int height = matrix.Height;
Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
}
}
return bmap;
}
이미지 워터마크 추가:
//
private Bitmap ImageWatermark(Bitmap map, string waterpath)
{
Image waterimg = Image.FromFile(waterpath);
//
Graphics g = Graphics.FromImage(map);
//
ArrayList loca = new ArrayList();
int x = 0;
int y = 0;
x = map.Width / 2 - waterimg.Width / 2;
y = map.Height / 2 - waterimg.Height / 2;
loca.Add(x);
loca.Add(y);
//g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), waterimg.Width, waterimg.Height));
g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), 75, 75));
return map;
}
내보내기:
saveFileDialog 컨트롤을 먼저 추가합니다.
private void btnOut_Click(object sender, EventArgs e)
{
try
{
saveFileDialog1.ShowDialog();
string fileName = saveFileDialog1.FileName;
if (fileName != null)
{
mapCreate.Save(fileName);//mapCreate bitmap
}
}
catch (Exception ex)
{
throw;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
해결js가 QR코드를 생성할 때 빈 div 문제를 정의해야 합니다qrcode의 설명에 따르면: QR코드를 저장하는 요소가 있어야 합니다. 이div에 canvas,img 두 개의 라벨이 추가된 것을 볼 수 있습니다. 근데 이div를 만들고 싶지 않아요?그리고 노드-qrcode를 찾...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.