回答
有一个Bitmap
构造函数重载,这需要你拥有的一切(加PixelFormat
):
public Bitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0);
这可能会实现(如果args.Buffer
是blittable类型的数组,像byte
为例):
Bitmap bitmap;
var gch = System.Runtime.InteropServices.GCHandle.Alloc(args.Buffer, GCHandleType.Pinned);
try
{
bitmap = new Bitmap(
args.Width, args.Height, args.Stride,
System.Drawing.Imaging.PixelFormat.Format24bppRgb,
gch.AddrOfPinnedObject());
}
finally
{
gch.Free();
}
更新:
Probabl y最好是将图像字节手动复制到新创建的Bitmap
,因为它好像构造函数没有这样做,并且如果byte[]
图像数据数组被垃圾收集,可能会发生各种不好的事情。
var bitmap = new Bitmap(args.Width, args.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
var data = bitmap.LockBits(
new Rectangle(0, 0, args.Width, args.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
if(data.Stride == args.Stride)
{
Marshal.Copy(args.Buffer, 0, data.Scan0, args.Stride * args.Height);
}
else
{
int arrayOffset = 0;
int imageOffset = 0;
for(int y = 0; y < args.Height; ++y)
{
Marshal.Copy(args.Buffer, arrayOffset, (IntPtr)(((long)data.Scan0) + imageOffset), data.Stride);
arrayOffset += args.Stride;
imageOffset += data.Stride;
}
}
bitmap.UnlockBits(data);
我所给出的是我可以在参数 中找到步幅/缓冲区等ie - > args .Buffer = buffer ... args.Stride = stride等 但是使用 位图测试=新的位图(args.Width,args.Height,args.Stride,PixelFormats.Rgb24,args.Buffer); 给了我一个错误:(我有点新的图像编程... – Mattb2291 2012-07-31 12:02:09
这个工作......好吧......让我到某个地方......? var test = BitmapFrame.Create(args.Width, args.Height,300D,300D,PixelFormats.Rgb24,null,args.Buffer,args.Stride); – Mattb2291 2012-07-31 12:14:49
'args.Buffer'' byte []'还有'System.Drawing.Bitmap'和'BitmapFrame '来自2个不同的GUI框架,你必须决定使用什么 – max 2012-07-31 12:18:26
,如果你有缓冲区的字节[],宽度和高度+的像素格式(跨步)这应该工作
public Bitmap CreateBitmapFromRawDataBuffer(int width, int height, PixelFormat imagePixelFormat, byte[] buffer)
{
Size imageSize = new Size(width, height);
Bitmap bitmap = new Bitmap(imageSize.Width, imageSize.Height, imagePixelFormat);
Rectangle wholeBitmap = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
// Lock all bitmap's pixels.
BitmapData bitmapData = bitmap.LockBits(wholeBitmap, ImageLockMode.WriteOnly, imagePixelFormat);
// Copy the buffer into bitmapData.
System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length);
// Unlock all bitmap's pixels.
bitmap.UnlockBits(bitmapData);
return bitmap;
}
- 1. 将WPF宽度/高度转换为VB 6宽度/高度
- 2. 将深度缓冲区转换为GLSL的深度纹理
- 3. Html高度缓冲区
- 4. 会话会保存缓冲区的宽度和高度吗?
- 5. 设置渲染缓冲区宽度和高度(Open GL ES)
- 6. 如何将视图宽度和高度转换为CGPoint坐标?
- 7. 将UIImage转换为8灰度像素缓冲区
- 8. 将深度渲染缓冲区复制到深度缓冲区
- 9. C#将幅度/相位转换为实数/虚数
- 10. 旋转位图android时获取位图的宽度和高度?
- 11. 试图将imagedata转换为高度图
- 12. 如何将BGRA缓冲区转换为RGBA缓冲区格式?
- 13. 缓冲区溢出缓冲区长度
- 14. android将文本宽度(以像素为单位)转换为屏幕宽度/高度的百分比
- 15. Emacs shell输出缓冲区高度
- 16. Node.js将缓冲区转换为Int8Array
- 17. 将ID3D11Texture2D转换为内存缓冲区
- 18. 将Scala缓冲区转换为Java ArrayList
- 19. 如何在OGRE中设置深度缓冲区(z缓冲区)的位宽/精度?
- 20. imageView中的位图高度和宽度
- 21. 确定位图的宽度和高度
- 22. 我如何获得比位图宽度小的步幅?
- 23. 从缓冲区转换为基址64使用角度阅读
- 24. Vulkan深度缓冲区位置重构
- 25. 如何获取/设置默认帧缓冲区的宽度和高度?
- 26. 将32bpp位图转换为16bpp(灰度)
- 27. 将字节[]转换为不知道宽度和高度的图像EmguCV
- 28. iOS:从OpenAL将音高移位和管道输出转换为缓冲区
- 29. C缓冲区C#位图对象
- 30. Android:将imageview转换为位图,灰度,将位图转换为imageview
HTTP://whathaveyoutried.com/...表现出一定的代码... – 2012-07-31 11:41:49
你的意思是说上传时想要以二进制格式将图像保存到数据库中,并检索值并显示为图像? – 2012-07-31 11:42:53
我的意思是有人编写了一个代码来获取摄像机的高度/宽度/跨度/缓冲区。他现在要我做点什么。我想使用位图图像,他使用writeablebitmap并告诉我如何获得步幅/宽度等... – Mattb2291 2012-07-31 12:04:19