简体   繁体   English

将字节数组转换为图像时出错,修改字节数组后,字节数组从c#中的图像本身获取

[英]error while converting the byte array to image ,after modifying the byte array and the byte array is taken from the image itself in c#

this is my code. 这是我的代码。 Here i hv formed the byte array of img, i am trying to add some vlue to this byte array say 10 and i'll take care that the value is not exceeding 255. later if i try to redraw the image via the following code i am getting error at this line... what can be the problem.. without modification if i try to draw the image it is coming but if i cahnge some value it is not drawing.. 我在这里形成了img的字节数组,我试图在此字节数组中添加一些vlue,例如10,我会注意该值不会超过255。稍后,如果我尝试通过以下代码重绘图像,我在此行出现错误...可能是问题所在..如果不做任何修改,如果我尝试绘制即将到来的图像,但是如果我发现一些值,则不会绘制。

public Image btoi(byte[] bt)
{
    ms = new MemoryStream(bt, 0, bt.Length);
    img = Image.FromStream (ms, true); // error at this line
    ms.Close();

    return img;
}

The image data can be stored in various formats, including a header wich describes the image data. 图像数据可以以各种格式存储,包括描述图像数据的标题。 If you want to change the RGB value of the pixels you have to first make sure that the image format you are using are indeed storing data in RGB format and second only manipulate those parts of the memory block that contains the RGB values. 如果要更改像素的RGB值,则必须首先确保所使用的图像格式确实以RGB格式存储数据,其次仅操作包含RGB值的内存块的那些部分。

If you alter the entire memory block you will probably overwrite the values indicating image width and height as well. 如果更改整个内存块,则可能会覆盖表示图像宽度和高度的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM