BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
int* colorData = (int*)bmData.Scan0.ToPointer();
#region 转为特征码
for (int i = 1; i < w; i++)
{
for (int j = 1; j < h; j++)
{
int index = j * b.Width + i;
if (colorData[index] < yansheqj)
{
icolor=colorData[index];
}
}
}
#endregion
}
b.UnlockBits(bmData);icolor的值也就是颜色.ToArgb()的值了,问题是:
icolor得到的是一个负整数,如何根据icolor得出该颜色的红色red分量呢?
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
int* colorData = (int*)bmData.Scan0.ToPointer();
#region 转为特征码
for (int i = 1; i < w; i++)
{
for (int j = 1; j < h; j++)
{
int index = j * b.Width + i;
if (colorData[index] < yansheqj)
{
icolor=colorData[index];
}
}
}
#endregion
}
b.UnlockBits(bmData);icolor的值也就是颜色.ToArgb()的值了,问题是:
icolor得到的是一个负整数,如何根据icolor得出该颜色的红色red分量呢?
解决方案 »
- 我有一个字符串,如何设置打印格式?
- dataGridView数据存于ACCESS?如何做最方便
- Web Service是否能实现像Socket那样来回的复杂的通信机制?
- 高分给treeview中的叶子节点加上onclick事件处理js函数
- 你们有没有碰到这样一个奇怪的问题
- DataGrid使用SetDataBinding方法运行时设置数据源,请问什么叫运行时?
- 三层绑定DropDownList问题
- 想学vs .net(C#)的智能设备开发,大家给点意见
- 三层架构中的数据校验怎么写到Model类中。net2.0环境。
- 在c#中,对于多文档窗口,如何判断子窗口已经带开,对于已打开的实例不再打开,在线等待
- c# 编码问题
- 一不小心把label的Text属性删了
byte Red=someColor.R;
那么
R=(byte)(icolor);
G=(byte)(((word)(icolor)) >> 8)
B=(byte)((icolor)>>16)
icolor = Convert.ToUInt32(colorData[index]);
有异常,值对于uint32太大或者太小了
{ // Create a new bitmap.
Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg"); // Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat); // Get the address of the first line.
IntPtr ptr = bmpData.Scan0; // Declare an array to hold the bytes of the bitmap.
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
��� byte[] rgbValues = new byte[bytes]; // Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); // Set every third value to 255. A 24bpp bitmap will look red.
for (int counter = 2; counter < rgbValues.Length; counter += 3)
rgbValues[counter] = 255; // Copy the RGB values back to the bitmap
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); // Unlock the bits.
bmp.UnlockBits(bmpData); // Draw the modified image.
e.Graphics.DrawImage(bmp, 0, 150); }
来自:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.scan0.aspx