Click here to Skip to main content
15,888,235 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

My database have Image Type Data. its not support on my richedit control. but its support Byte[] formate. now My Richedit control image data will show like this

System.Drawing.Bitmap

its show me image formate text only. it doesnt show me the image. so i'm trying to convert it through coding. But i couldn't Help me plz

Code:

C#
DocumentImageCollection imags = richEditControl1.Document.GetImages(richEditControl1.Document.Range);

              for (int i = 0; i < imags.Count; i++)
              {
                 //Got exception in this line
                 byte[] Imgdata = File.ReadAllBytes(imags[i].Image.ToString());
                  if (imags.Count > i)
                      if (documentImage != null)
                      {
                          Image s = new Bitmap(Imgdata.ToString());
                      }
                  richEditControl1.Document.InsertPicture(richEditControl1.Document.CaretPosition, (Image)documentImage);


C#
DocumentImageCollection images = richEditControl1.Document.GetImages(richEditControl1.Document.Range);

	for (int i = 0; i <= images.Count - 1; i++) {
		Image newImage = images(i).Image.NativeImage.GetThumbnailImage(100, 100, null, IntPtr.Zero);

		DocumentPosition start = images(i).Range.Start;

		richEditControl1.Document.Delete(images(i).Range);
		richEditControl1.Document.InsertImage(start, newImage);
	}

I run this code i got exception under images(i).
Method,Delegate,Event Expected.

I tried multiple way. but i'm unable to achieve my goal.
Posted
Updated 21-Feb-13 0:46am
v3
Comments
Mitchell J. 21-Feb-13 5:52am    
Have you tried System.Drawing.ImageConverter?
sencsk 21-Feb-13 5:56am    
How to implement this. can u implement in my code
Mitchell J. 21-Feb-13 6:02am    
Just google "ImageConverter C#" and you'll get the basics. It's pretty easy to use.
Example:
ImageConverter c = new ImageConverter();
byte[] Imgdata = (byte[])c.ConvertTo(new Bitmap(0, 0), typeof(byte[]));
sencsk 21-Feb-13 6:10am    
I got this exception
Unable to cast object of type 'DevExpress.XtraRichEdit.API.Native.Implementation.NativeDocumentImageCollection' to type 'System.Drawing.Image'.

My code:

DocumentImageCollection imags = Richeditcontrol1.Document.GetImages(Richeditcontrol1.Document.Range);

byte[] Buffer = (byte[])new ImageConverter().ConvertTo(imags,typeof(byte[]));
sencsk 21-Feb-13 6:42am    
DocumentImageCollection images = richEditControl1.Document.GetImages(richEditControl1.Document.Range);

for (int i = 0; i <= images.Count - 1; i++) {
Image newImage = images(i).Image.NativeImage.GetThumbnailImage(100, 100, null, IntPtr.Zero);

DocumentPosition start = images(i).Range.Start;

richEditControl1.Document.Delete(images(i).Range);
richEditControl1.Document.InsertImage(start, newImage);
}

I run this code i got exception under images(i).
Method,Delegate,Event Expected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900