using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace CS_ConsoleTest
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct StPoint
public Int64 X, Y;
public StPoint(Int64 _x, Int64 _y) { X = _x; Y = _y; }
public class ImageWarp
// using System.Drawing;
// using System.Drawing.Imaging;
public Bitmap bmp;
public Graphics gph;
public ImageWarp(Int32 width, Int32 height)
bmp = new Bitmap(width, height);
gph = Graphics.FromImage(bmp);
gph.Clear(Color.Empty);
public void DrawPoint(StPoint pt, Color color, Single thickness = 1.0f)
gph.DrawEllipse(new Pen(color, thickness), (int)pt.X - thickness * 0.5f, (int)pt.Y - thickness * 0.5f, thickness, thickness);
//gph.FillEllipse();
public void DrawLine(StPoint p0, StPoint p1, Color color, Single thickness = 1.0f)
gph.DrawLine(new Pen(color, thickness), p0.X, p0.Y, p1.X, p1.Y);
public void DrawPolygon(StPoint[] points, Color color, Single thickness = 1.0f)
gph.DrawPolygon(new Pen(color, thickness), DataWarp.ToWinPoints(points));
public void Save(string filename)
gph.Save();
gph.Dispose();
bmp.MakeTransparent(Color.Transparent);
bmp.Save(filename, ImageFormat.Png);
public static void Demo01()
ImageWarp image = new ImageWarp(512, 512);
image.DrawLine(new StPoint(256, 0), new StPoint(256, 511), Color.Blue, 1.0f);
image.DrawLine(new StPoint(0, 256), new StPoint(511, 256), Color.Red, 1.0f);
image.DrawPoint(new StPoint(256, 256), Color.Green, 2.0f);
image.DrawPoint(new StPoint(0, 0), Color.Black, 10.0f);
image.Save("ImageWarp.Demo01.png");
main函数:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS_ConsoleTest
class Program
static void Main(string[] args)
ImageWarp.Demo01();
// Mylaf
// 2019-11-08 厦门
环境:Windows 10 x64, VS2017问题:使用C#语言将图像数据写入到PNG格式的图片文件中代码:// Mylaf using System;using System.Collections.Generic;using System.Runtime.InteropServices;using System.Drawing;using System.Drawin...
数据库的Image字段保存的是字节,所以写入数据库Image字段和从数据库Image字段读取的内容都应该为字节.
1、数据库Image字段读写文件
写文件:写文件的过程为将文件以流文件形式打开并将内容读取到一个byte数组,然后将此byte数组写入数据库的Image字段。
FileInfo
///ImageData:图片的byte数组数据
///imageName:图片保存的路径
private void SaveImage(byte[] ImageData, string imageName)
//保存图片到本地文件夹
System.IO.MemoryStream ms = new System.IO.Memor
在一些应用设计中肯定会运用到图片,就以窗体应用为例,加入图片的方式有:
1.直接通过图片所在的位置进行添加;
格式: this.BackgroundImage = Image.FromFile(@"盘符:\文件夹名\照片名称");
例如: this.BackgroundImage = Image.FromFile(@"C:\Users\Desktop\博客编辑\1.jpg");
2.通过在...
private void btnSavePng_Click(object sender, EventArgs e)
// cat.png feather.png Format32bppArgb
string strOldFilePath = @"D:\icon\colorpen.jpg";
Image img = Image.FromFile(Application.StartupPath + "\\Sig.png");
using (var bmp = new Bitmap(img.Width, img.Height))
其实可以直接把数据写在图片里!
做法很简单!我写了点代码,大家可以参考下!
https://hub004.xindong.com/yangyiqiang/AvatarTool/blob/master/src/utils/As3PngEncoder.as
原理就是把PNG数据格式中的IEND给替换成你要
Sharp代码
StreamWriter是一个用于将数据写入文本文件的类。在C#中,您可以使用StreamWriter类来写入文本文件,下面是一个基本的示例代码:
using System;
using System.IO;
class Program
static void Main(string[] args)
string filePath = @"C:\Users\UserName\Desktop\example.txt";
using (StreamWriter writer = new StreamWriter(filePath))
writer.WriteLine("Hello World!");
以上代码可以将字符串“Hello World!”写入名为“example.txt”的文本文件中。请注意,使用“using”语句可以确保StreamWriter实例在使用后被正确释放。
CSDN-Ada助手:
制作OpenCV相机标定板棋盘格图像
mylaf:
制作OpenCV相机标定板棋盘格图像
mylaf:
制作OpenCV相机标定板棋盘格图像
m0_52689550:
MathGL在Windows下的编译
Amillton: