PDA

View Full Version : خواندن و نوشتن عکس بصورت باینری



dr_csharp
سه شنبه 15 آبان 1386, 16:01 عصر
سلام دوستان . من یه عکس و بصورت باینری باز میکنم و میخوام یکجا دیگه ذخیره کنم . ولی الان وقتی عکس جدید و میسازم از نظر سایز درسته ولی عکسی نشون نمیده !

hassan razavi
سه شنبه 15 آبان 1386, 19:19 عصر
کد یا پروژتون رو بذارید تا بررسی کنیم.

dr_csharp
چهارشنبه 16 آبان 1386, 07:39 صبح
private void button1_Click(object sender, EventArgs e)
{
System.IO.FileStream fs;
fs = new System.IO.FileStream("C:\\1.gif",
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read);

byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();

byte[] myData = new byte[rawData.Length];
WriteToFile(ref myData);

}

private void WriteToFile(ref byte[] Buffer)
{

FileStream newFile;
newFile = new FileStream("C:\\2.gif", FileMode.Create,
System.IO.FileAccess.Write);

newFile.Write(Buffer, 0, System.Convert.ToInt32(Buffer.Length));
newFile.Close();


}

hassan razavi
چهارشنبه 16 آبان 1386, 10:46 صبح
برای ذخیره از روش زیر استفاده کنید :



MemoryStream ms=New MemoryStream(Buffer,0,Buffer.Lenght);
Image im=new Image.FromStream(ms);
im.SaveToFile(path);

dr_csharp
چهارشنبه 16 آبان 1386, 11:10 صبح
برای ذخیره از روش زیر استفاده کنید :



MemoryStream ms=New MemoryStream(Buffer,0,Buffer.Lenght);
Image im=new Image.FromStream(ms);
im.SaveToFile(path);



من اینکار رو قبلا انجام دادم ولی متاسفانه جواب نداد :


FileStream newFile = new FileStream("C:\\2.gif", FileMode.Create, System.IO.FileAccess.Write);

MemoryStream newFile = new MemoryStream();
newFile.Write(Buffer, 0, Buffer.Length);
Bitmap bitmap = new Bitmap(newFile);
bitmap.Save("C:\\2.gif", System.Drawing.Imaging.ImageFormat.Gif);
newFile.Close();