本文介绍了如何将新的字节数组转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-SA
You are using correct approach, but only in two lines related to MemoryStream and the fragment where you read bytes from a file. Everything else is some gibberish I cannot understand. Throw it out and you will have a working solution. If you have some problems, use the debugger.
—SA
我已编写此代码用于提取图像的bitplane1。但我有例外
i have write this code for extracting bitplane1 of my image . but i have exception
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Collections; namespace bitplane { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Image grayImage; OpenFileDialog o = new OpenFileDialog(); o.ShowDialog(); byte[] x = File.ReadAllBytes(o.FileName); byte maskbyte1 = 2; int [] newpix= new int [x.Length]; for (int i = 0; i < x.Length; i++) { newpix[i] = x[i] & maskbyte1; string px=newpix[i].ToString(); x[i] = Convert.ToByte(px); } MemoryStream ms = new MemoryStream(x); Image myImage = Image.FromStream(ms); myImage.Save(@"C:\Users\Public\Pictures\Sample Pictures\New folder\fgh.jpg"); } } }推荐答案
使用httphandler中的以下代码将字节数组转换为图片 use the below code in httphandler to convert byte array to image context.Response.ContentType = "image/jpeg";//get image content type of selected file Stream strm = new MemoryStream(x); byte[] buffer = new byte[4096]; int byteSeq = strm.Read(buffer, 0, 4096); while (byteSeq > 0) { context.Response.OutputStream.Write(buffer, 0, byteSeq); byteSeq = strm.Read(buffer, 0, 4096); }
您使用的方法正确,但只有两行与 MemoryStream相关以及从文件中读取字节的片段。其他一切都是我无法理解的一些胡言乱语。扔掉它,你将有一个有效的解决方案。如果您遇到问题,请使用调试器。
更多推荐
如何将新的字节数组转换为图像
发布评论