Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW to Add Binary Image to your Custom Control??? 1

Status
Not open for further replies.

lito247

Programmer
May 21, 2004
10
US
I am creating a custom control (pop up calendar) and it has a few images that go inside the calendar, I want it to be completely self contained...

I converted the images to a base64 encoded binary strings and have a function that would take the string and convert it back to binary.

I am having trouble returning object of System.Web.UI.WebControls.Image type... because the image is created using System.Drawing.Image class. Is there a way to have this done all in one file? I saw some examples where they make a page return mime type and them write out the stream, I was hoping there is a better way of doing it for my application.

I have tried many approaches to convert data types Drawing.Image to WebControl.Image but without much luck.

Any Suggestions?
-Lito
 
Use ImageList control, to store images
Set the right size to it and then you can use as you wish.

Code:
 myImageContainer.Image=imageList1.Images[0];
 myImageContainer.Image=imageList1.Images[1];
 ...

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Forgot to mention that you can also store image data in an Resource File.
(Add new Item -> Asembly Resource file)

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thanks for a quick reply,
I am developing for the web and System.Windows is not available to me which contains the ImageList control.

Also I am able to store images in a string (base64 encoded) and able to display them back to the screen using Response.BinaryWrite() but the problem is it will only display image(s). I need to be able place the image into a placehoder or an image control, which I am not able to accomplish.

Thanks,
Lito
 
You can use Bitmap object to add your dataStream
Code:
System.IO.StreamWriter sw=new System.IO.StreamWriter();
sw.Write(srtData);
Bitmap b=new Bitmap(sw.BaseStream);
//use b in your control

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
shadow thank you once again for coming back and replying, I must be getting stupider by the minute, because for the lide of me I can't figure out how I can use "Bitmap b" in my control.

For example
In my application I have some JavaScript code that contains functions for this DHTML popup and one of them is a to close the popup layer via clicking on the image.

In my code I have the following
calJS is a StringBuilder object...

calJS.Append(" \r\n"+"<a href='javascript:hideCalendar()'>"+ b +"</a>");

the above would not work... it just displays "System.Drawing.Bitmap" instead of the picture.

I have also tried...
calJS.Append(" \r\n"+"<a href='javascript:hideCalendar()'>"+ this.Controls.Add(b) +"</a>");
which throws an exception error, something about
System.Drawing.Image not able to be converted to Sytem.Web.UI.WebControls

Any other suggestions?
Thanks,
Lito

 
I dont knw what you wanna do with that control and why you would need to add a picture to it since you can reference an image by an aspx file as you told before.
Code:
 <img src="getimage.aspx?id=1">

where your getimage.aspx file will decode your base64 coded file and outpus with BinaryWrite it's content.
Other then that you should check on ASP.NET forum.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top