PDA

View Full Version : تبدیل image به byte[]



shirin_h
چهارشنبه 12 دی 1386, 17:08 عصر
سلام
چطور می توان image ای را که در picturebox است و مسیرش را نمی دانیم به byte[] تبدیل کنیم
اگه می شه کد بذارین چون نمی تونم وقت بزارم
ممنون.

raravaice
چهارشنبه 12 دی 1386, 17:22 عصر
Dim image1 As System.Drawing.Image
image1 = PictureBox1.Image
Dim bitmap1 As New Bitmap(image1)


:لبخند::چشمک:

raravaice
چهارشنبه 12 دی 1386, 17:51 عصر
سلام
تکمیل کد بالا



Dim image1 As System.Drawing.Image
image1 = PictureBox1.Image
Dim bitmap1 As New Bitmap(image1)
Dim h, w, i, j As Integer
h = bitmap1.Height
w = bitmap1.Width
Dim arrA(w, h) As Integer
Dim arrR(w, h) As Integer
Dim arrG(w, h) As Integer
Dim arrB(w, h) As Integer
For i = 0 To w - 1

For j = 0 To h - 1
arrA(i, j) = bitmap1.GetPixel(i, j).A
arrR(i, j) = bitmap1.GetPixel(i, j).R
arrG(i, j) = bitmap1.GetPixel(i, j).G
arrB(i, j) = bitmap1.GetPixel(i, j).B

Next

Next

shirin_h
چهارشنبه 12 دی 1386, 19:33 عصر
ممنونم
ولی کسی جور دیگه ای بلد نیست
این کد به نظرم یه جوریه.

Leo_messi
چهارشنبه 12 دی 1386, 22:20 عصر
ببین این بدرت میخوره

MemoryStream mstr = new MemoryStream();
pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat);

byte[] arrImage = mstr.GetBuffer();

sinpin
چهارشنبه 12 دی 1386, 22:56 عصر
سلام
تکمیل کد بالا



Dim image1 As System.Drawing.Image
image1 = PictureBox1.Image
Dim bitmap1 As New Bitmap(image1)
Dim h, w, i, j As Integer
h = bitmap1.Height
w = bitmap1.Width
Dim arrA(w, h) As Integer
Dim arrR(w, h) As Integer
Dim arrG(w, h) As Integer
Dim arrB(w, h) As Integer
For i = 0 To w - 1

For j = 0 To h - 1
arrA(i, j) = bitmap1.GetPixel(i, j).A
arrR(i, j) = bitmap1.GetPixel(i, j).R
arrG(i, j) = bitmap1.GetPixel(i, j).G
arrB(i, j) = bitmap1.GetPixel(i, j).B

Next

Next



عجب کد با مزه ای !:چشمک:
اگه واسه همچین کار کوچیکی لازم بود اینهمه منابع رو مصرف کنیم (حافظه و پروسسور) که دیگه بقول قدیمیا "سنگ رو سنگ بند نمیشد"

Amir Oveisi
چهارشنبه 12 دی 1386, 23:35 عصر
یه مثال کوچولو

ImageConverter ic = new ImageConverter();
record.Image = (byte[])ic.ConvertTo(pictureBox1.BackgroundImage, typeof(byte[]));

hassan razavi
چهارشنبه 12 دی 1386, 23:45 عصر
در کد زیر Image در یک آرایه ای از جنس Byte بنام b قرار میگیرد


System.IO.MemoryStream ms=new System.IO.MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] b=new byte[ms.Length];
ms.Position = 0;
ms.Read(b, 0, Convert.ToInt32(ms.Length));

myoosef
پنج شنبه 10 مهر 1393, 11:19 صبح
سلام ببخشید میشه بگید وقتی تبدیلش کردیم چطور به حالت اول برگردونیم

alireza_g698
پنج شنبه 10 مهر 1393, 11:49 صبح
ســــــــــــــــــــــــ ــلام
اولusing System.IO;

بعد


Image oImage = pictureBox1.Image;
MemoryStream stream=new MemoryStream();
oImage.Save(stream,ImageFormat.Jpeg);
byte[] buffer = stream.ToArray();