将byte []复制到bimtap中的某个位置 [英] Copy byte[] to a location in a bimtap

查看:98
本文介绍了将byte []复制到bimtap中的某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字节[]代表​​位图。我想将它们复制到一个位图中,将它们放在一起。元帅有可能吗?请参阅下面的代码,了解我希望它如何工作。在此先感谢。



I have two byte[] that represent bitmaps. I want to copy them in to one bitmap, placing them next to each other. Is this possible with marshal? See the code below for how i'd like it to work. Thanks in advance.

//Bitmap 100x100
            byte[] frame1 = null;
            //Bitmap 100x100
            byte[] frame2 = null;

            using (Bitmap bmp = new Bitmap(200, 100))
            {
                BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

                //I want to copy frame1 to location 0,0 in the bitmap
                Marshal.Copy(frame1, 0, bmpData.Scan0, frame1.Length);

                //I want to copy frame2 to location 100,0 in the bitmap
                Marshal.Copy(frame2, 0, bmpData.Scan0, frame2.Length);

                bmp.UnlockBits(bmpData);
            }





我的尝试:



我有两个字节[]代表​​位图。我想将它们复制到一个位图中,将它们放在一起。元帅有可能吗?请参阅下面的代码,了解我希望它如何工作。在此先感谢。



What I have tried:

I have two byte[] that represent bitmaps. I want to copy them in to one bitmap, placing them next to each other. Is this possible with marshal? See the code below for how i'd like it to work. Thanks in advance.

推荐答案

没有必要使用Marshal,你可以使用这样的东西:
It is not necessary to use Marshal, you can use something like this:
graphics.DrawImage (
			bitmap,
			new Rectangle ( 0, 0, Width, Height ),
			new Rectangle ( 0, 0, Width, Height ),
			GraphicsUnit.Pixel );



因为这对你来说可能太慢了,也许这会更符合你的喜好: .NET中的快速无指针图像处理 [ ^ ]


将图像放在一起的最简单的快速解决方案可能就是使用 Bitmap.BitBlt方法 [ ^ ]。这意味着您必须首先将byte []数组转换为位图,但是如上所述使用 LockBits 方法应该足够简单。试图将图像并排放入最终位图的数据是很棘手的,因为您需要循环遍历结果的每一行,一次从每个数组复制一行数据。
Probably the easiest fast solution for putting the images next to each other would be to use the Bitmap.BitBlt Method[^]. This means that you would have to convert the byte[] arrays to bitmaps first, but using the LockBits method as you do above should make that simple enough. Trying to put the images side-by-side going directly into the final bitmap's data is tricky, as you would need to loop through each row of the result, copying one line of data from each array at a time.


这篇关于将byte []复制到bimtap中的某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆