Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Permenkaret Permenkaret is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 351
Rep Power: 14
Permenkaret mempunyai hidup yang Normal
Default [Share] Menampilkan Image dari XTraGrid ke PictureEdit (DevExpress)

ijinkan nubi ikut nimbrung gan...



Gimana caranya menampilkan gambar/picture yang ada di gridcontrol ke pictureedit ?



informasinya, salah satu kolom di gridcontrol itu repository item nya pake picture edit. nah... pada saat event click di gridcontrol, gambarnya itu muncul di picture edit yg ada di form.




Spoiler for gambarannya:












secara umum, kalau kita ingin menampilkan text dari gridcontrol ke textbox adalah dengan menggunakan :

Dim row =GridView1.GetDataRow(GridView1.FocusedRowHandle)

TextBox1.Text = row(0)


*pada row(0), nilai 0 adalah index dari kolom di xtragrid



Tetapi, kalau syntax diatas digunakan untuk menampilkan gambar, hasilnya error gan...

contohnya :

Dim row =GridView1.GetDataRow(GridView1.FocusedRowHandle)

PictureEdit1 = row(1)


*contohnya pada row(1), nilai 1 adalah index dari kolom di xtragrid yg berisi repository picture edit



ternyata oh ternyata...

type data yg ada di kolom gambar tersebut adalah byte(), bukannya text.

jadi untuk menampilkan gambar dari grid ke picture edit, perlu dilakukan konversi dari byte ke image dulu.

ini syntax yg ane pake buat konversi byte ke image :



-- begin --



Public Function ByteToImage(ByVal ByteArr() As Byte) As Image

--Dim ImageStream As MemoryStream

--Try

----If ByteArr.GetUpperBound(0) > 0 Then

------ImageStream = New MemoryStream(ByteArr)

------Return Image.FromStream(ImageStream)

----Else

------Return Nothing

----End If

--Catch ex As Exception

----Return Nothing

--End Try

End Function



-- end --



akhirnya... syntax untuk menampilkan image dari xtragrid ke pictureedit (event grid click) adalah :

Dim row = GridView.GetDataRow(GridView.FocusedRowHandle)

PictureEdit.Image = ByteToImage(row(1))




Ini ane sertakan juga syntax buat konversi image ke byte, siapa tau ada agan2 yg butuh



Public Function ImageToByte(ByVal LoadImage As Image) As Byte()

--Dim imageStream As MemoryStream = New MemoryStream()

--Try

----LoadImage.Save(imageStream, ImageFormat.Jpeg)

----imageStream.Close()



----Dim imageByteArray As Byte() = imageStream.ToArray()

----imageStream.Dispose()



----Return imageByteArray

--Catch ex As Exception

----Return Nothing

--End Try

End Function



segitu dulu agan2...







Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 02:01 PM.


no new posts