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");
}
}
}
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");
}
}
}