C# Can';t从复制的像素创建新位图
我有一张图片,我想在其中存储一条消息(通过更改每个像素所需的最后有效位)。我正在使用位图将像素加载到列表中C# Can';t从复制的像素创建新位图,c#,image,bitmap,pixel,bitmapimage,C#,Image,Bitmap,Pixel,Bitmapimage,我有一张图片,我想在其中存储一条消息(通过更改每个像素所需的最后有效位)。我正在使用位图将像素加载到列表中 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string oEcrypt; private string oDecrypt; private List<ARGB> toCipherLis
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string oEcrypt;
private string oDecrypt;
private List<ARGB> toCipherList = new List<ARGB>();
private int Width;
private int Height;
private void button1_Click(object sender, EventArgs e)
{
// here i'm editing toCipherList
Bitmap img = new Bitmap(Width, Height);
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
Color pixel = Color.FromArgb(toCipherList[i].A, toCipherList[i].R, toCipherList[i].G, toCipherList[i].B);
img.SetPixel(i, j, pixel);
}
}
img.Save("output.jpg");
}
private void button3_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
oEcrypt = openFileDialog1.FileName;
textBox3.Text = oEcrypt;
Bitmap img = new Bitmap(oEcrypt);
Width = img.Width;
Height = img.Height;
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
Color pixel = img.GetPixel(i, j);
byte A = pixel.A;
byte R = pixel.R;
byte G = pixel.G;
byte B = pixel.B;
ARGB rGB = new ARGB(A, R, G, B);
toCipherList.Add(rGB);
}
}
}
public class ARGB
{
public byte A { get; set; }
public byte R { get; set; }
public byte G { get; set; }
public byte B { get; set; }
public ARGB(byte a, byte r, byte g, byte b)
{
this.A = a;
this.R = r;
this.G = g;
this.B = b;
}
}
公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
}
私有字符串密码;
私有字符串密码;
私有列表,但它对我不起作用,或者我做错了什么。这里有很多更好的方法。但是,列表是你的问题。简而言之,你没有阅读每个元素。试试这个
var index = 0;
...
// loops here
Color pixel = Color.FromArgb(toCipherList[index].A, toCipherList[index].R, toCipherList[index].G, toCipherList[index].B);
index++;
一些提示
使用锁具更快
使用32bpp,您的像素可以存储为整数
不要为ARGB类操心,请参见上文
这里有很多更好的方法。但是您的问题在于列表。简而言之,您没有阅读每个元素。请尝试以下方法
var index = 0;
...
// loops here
Color pixel = Color.FromArgb(toCipherList[index].A, toCipherList[index].R, toCipherList[index].G, toCipherList[index].B);
index++;
一些提示
使用锁具更快
使用32bpp,您的像素可以存储为整数
不要为ARGB类操心,请参见上文
哦,天哪,那太尴尬了。谢谢你的提示,我真的很感激!哦,天哪,那太尴尬了。谢谢你的提示,我真的很感激!