//byte[] buffer MemoryStream ms= new MemoryStream(buffer); Bitmap flag = new Bitmap(ms); pictureBox1.Image = flag;
再仔细说说要求:这是通过picturebox打开图片后,开辟内存,再转存到数组中的代码: Bitmap bmp= (Bitmap)pictureBox21.Image; Bitmap result; result = new Bitmap(bmp); Rectangle rect = new Rectangle(0, 0, width, height); System.Drawing.Imaging.BitmapData bmpData = result.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); IntPtr ptr = bmpData.Scan0; int bytes = bmpData.Stride * bmpData.Height; byte[] rgbValues = new byte[bytes]; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);//将指针指向的内存的图复制到数组中//通过操作数组处理图片System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);//将数组中的图复制到指针指向的内存中 result.UnlockBits(bmpData); pictureBox21.Image = result;//显示处理完的图片现在要求变了,图片在数组里,需要开辟一块新的空白内存来接收数组,处理,并最终显示在picturebox中,怎么做啊?
3楼,按你的代码写,这一句报错Bitmap flag = new Bitmap(ms);说是参数无效
byte []buffer =File.ReadAllBytes(@"C:\1.bmp"); MemoryStream ms = new MemoryStream(buffer); Bitmap flag = new Bitmap((Stream)ms); pictureBox1.Image = flag;测试通过
MemoryStream ms= new MemoryStream(buffer);
Bitmap flag = new Bitmap(ms);
pictureBox1.Image = flag;
Bitmap bmp= (Bitmap)pictureBox21.Image;
Bitmap result;
result = new Bitmap(bmp);
Rectangle rect = new Rectangle(0, 0, width, height);
System.Drawing.Imaging.BitmapData bmpData = result.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
IntPtr ptr = bmpData.Scan0;
int bytes = bmpData.Stride * bmpData.Height;
byte[] rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);//将指针指向的内存的图复制到数组中//通过操作数组处理图片System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);//将数组中的图复制到指针指向的内存中
result.UnlockBits(bmpData);
pictureBox21.Image = result;//显示处理完的图片现在要求变了,图片在数组里,需要开辟一块新的空白内存来接收数组,处理,并最终显示在picturebox中,怎么做啊?
byte []buffer =File.ReadAllBytes(@"C:\1.bmp");
MemoryStream ms = new MemoryStream(buffer);
Bitmap flag = new Bitmap((Stream)ms);
pictureBox1.Image = flag;测试通过