Now i have some images and i have a database (MS Access)

i need to convert all images to !one byte array!(couse i have 1 column for images) and i save this array. Then when i need a picture i should take some pic on this byte array.

umm i think i cant explain my status :)

i need to cut this byte array like split function. so then i can choose image whatever i want

:D

Thanks for Helps

Pass every image to this method bellow:

'in your method:
Private bImage As byr() = ImageToByteArray(yourImage)

'method
Public Function ImageToByteArray(imageIn As System.Drawing.Image) As Byte()
	Dim ms As New MemoryStream()
	imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
	Return ms.ToArray()
End Function

Thx a lot

now i can convert byte and i can save byte array to DB n i can take this from database

hmm now i have a problem : how can i separate this images?

thanks a lot for helping

hmm now i have a problem : how can i separate this images?

What do you mean? Dont you have images in a ImageList or something?

Public Sub imagestobyte(ByVal images() As Image)
        Dim flag As Integer
        Dim ms As New MemoryStream
        Dim i As Integer = 0
        For Each image In images
            images(i).Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            i += 1
        Next

        Dim bytes() As Byte = ms.ToArray
        Dim img As String = Convert.ToBase64String(bytes)
        Dim cmd As New OleDbCommand("UPDATE patients SET Pictures= '" & img & "' where ID = 0;", Form1.baglanti)
        'cmd.ExecuteNonQuery() 
        flag = cmd.ExecuteNonQuery
        If flag = 1 Then
            MsgBox("Saved..........")
        End If
        'Dim a As Image = Image.FromStream(ms)
        'Form1.PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
        'Form1.PictureBox2.Image = a
    End Sub


Public Sub bytetoimage()
        Dim da As New OleDbDataAdapter("Select Pictures From patients where ID = 0", Form1.baglanti)
        Dim dt As New DataTable
        Dim ms As New MemoryStream
        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            Dim arrimage() As Byte = dt.Rows(0).Item(0)
     
            For Each ar As Byte In arrimage
                ms.WriteByte(ar)
            Next
            Dim a() As Byte

            'Dim arr() As String = BitConverter.ToString(arrimage).Split("&") is useless
            Dim enctxt As New System.Text.UTF8Encoding()
            a = enctxt.GetBytes(arr(0))
            Dim ms2 As New MemoryStream
            ms2.Write(a, 0, a.Length)
            Form1.RichTextBox1.Text = arr(0)
            Form1.PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
            Dim img As Image = Image.FromStream(ms2)
            Form1.PictureBox2.Image = img
         
        Else
            MsgBox("not found...")
        End If


    End Sub

here are my subs
did u understand my mistake? :)

Edited 5 Years Ago by Oneryavuz: n/a

Do you wanna add only one picture?
why you call this code:

byte[] arrimage = dt.Rows[0][0];

As far as I can see from this code, you get image(s) from dataBase. And you wanna show it/them in pictureBox.
Only one, or you wanna show more? If more, then you create a button Next and Back to loop through images (and data of Patients - if there are any).

Am I right?

ok u r right hmm i edited my post i add my save sub if u look this u could understand why i use

byte[] arrimage = dt.Rows[0][0];

code or im stupid lol :D and Thank you for your interest my problems

You still didnt answer on ny question: Do you wanna loop through the images of patients? Will you have any buttons (Next, Back)?

If you you can do an ImageList, and loop through them while pressing on one of those tow buttons.

now i have some dental patients and i have their photos and dental pictures i need to save this 1 column couse i dont know how much pictures needed for 1 patient in my program i browse image on open file dialog and i need to save this image with other pictures in 1 column up to here i havent problem but i want to take my images in 1 column so first i need to take byte array (my byte array is (1st image to bytearray)+(2nd image to byte array)+...) and i need to split this images and save a image array. and i wanna use this image array :D

could i tell my problem (and sorry for my bad english i dont know really well this language :) )(Again Thx A LOT)

If you wanna store more picture of one patient, you cannot (or its not a good practice) to store more then one into one cell of a table.
Instead of that, I strongly suggest you to create a new Table which will be only for patient`s images. It will have only a foreigh key of patient, image name, and image it self (in byte array).

This way you can store as many pictures as you like for one patient. So DB shoud look like:

TABLENAME: field1, fields2, ...

PATIENT: PatientID, Name, LastName, ...
PATIENT_PICTURES: PatientID_FK(int), ImageName(varchar,50), Picture(byte)

You got my point?

yea you r right mybe its easier then my method thx ill try to do like this if i have any problem could i pm u?

Oh i found somethink usefull i add new column and i save there images byte array lenght like ( "3200,3300,2200") as string and if need 3th picture i ll call from my images byte arrays members 6500 to 8700 so i can save as many images iwant. just with using 2 column

This question has already been answered. Start a new discussion instead.