Solved

convert System.Drawing.Image to System.Web.UI.WebControls.Image

Posted on 2009-05-06
6
5,311 Views
Last Modified: 2013-11-08
I have an image in System.Drawing.Image control

How can I show it in
System.Web.UI.WebControls
0
Comment
Question by:KaranGupta
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24312085
My choice of action would be (assuming they are not in the same application, because you seem to be mixing ASP.NET with WinForms) is to save the Drawing.Image to disk as JPG or PNG and to add that as a link to the Web.UI.WebControls.Image.
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 24312091
hi  KaranGupta,

                        follow the below link.


http://forums.asp.net/t/578390.aspx
0
 

Author Comment

by:KaranGupta
ID: 24312102
Hi abel

My requirement is not to save the image on disk

Actually My scenario is I have an image.

I have converted the image into byte[] using this code

Bitmap bmp = new Bitmap("c:\\empty.jpg");        
        byte[] rawData;
        using (MemoryStream ms = new MemoryStream())
        {
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            rawData = ms.GetBuffer();
        }

Now I want to load this image to the Image web control How can I do that
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:KaranGupta
ID: 24312105
Hi tapanpattanaik

I have already seen that link but this is not useful.
0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24312126
> Now I want to load this image to the Image web control How can I do that
you cannot. The webcontrol takes a link to an image (which is why I suggested to store it locally). The other alternative is to create a HttpRequestHandler that creates this image on-the-fly and serves it as a link to your Image web control.

A web page is toally different then a winforms application. It's components work by just laying themselves out on the canvas of the HTML page. And HTML cannot do images, it can only do urls to images. Which is what the Image web control does: it renders itself to the html page as an img tag with a src attribute, which must be present on the server. That "present on the server" can arranged "on the fly" if need be, but then you need a HttpRequestHandler.
0
 
LVL 39

Expert Comment

by:abel
ID: 24312135
There are many such code examples on the net (google for request handler image). One such examples is this one, it includes a step-by-step on how to configure IIS: http://www.c-sharpcorner.com/UploadFile/desaijm/HTTPHandlersForImages11152005062705AM/HTTPHandlersForImages.aspx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set value of dynamically created checkboxlist 2 31
Graphics 2 27
C# bracket error 3 30
Help with converting xml file to excel using VB.NET 3 17
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question