C# - Add Bitmap To HTML?

Jun 23, 2010

I have an ASP.NET web form. This web form has an event handler that generates some HTML. This HTML is based on the time-of-day, that is why it is created in the event handler. Based on the time of day, an image is created programmatically via the following method:

private Bitmap GetImageForTime(DateTime time)
{
Bitmap bitmap = new Bitmap();
// Dynamically build the bitmap...
return bitmap;
}

want to call this method when the HTML is being generated. However, I do NOT want to write the image on the server. Instead, I would like to figure out a way to write it out along with the HTML. In a sense, I'm trying to accomplish the following:

protected void myLiteral_Load(object sender, EventArgs e)
{
string html = "<table><tr><td>";
html += GetImageForTime(DateTime.Now); // This is the problem because it's binary.
html += "</td><td>";
html += GetWeatherHtmlText();
html += "</td></tr></table>";
myLiteral.Text = html;
}

View 6 Replies


Similar Messages:

Web Forms :: Converting Bitmap To Ehm.bitmap

May 5, 2010

I have a colorpicker.png file and track the pixel clicked in codebehind using GetPixel. Works like a charm, but I read that converting to a bitmap on the fly is rather heavy on the server. Therefore I saved my .png file as a .bmp as well, so that a converted file would already exist. However, I don't seem tobe able to just use the bitmap file, but need to create a new bitmap from the bitmap...

My question is: The code below works (I provide it here for those who might need it - simply add the code below to codebehind and this code in your aspx page <asp:ImageButton

ID="cpRubrik"
runat="server"
ImageUrl="~/img/colorpicker.png"
/> ;

also note that the image can be whatever you want - a photo or a screendump of a colorpicker from say Photoshop or VS; and note that it's wise to put everything you need in an updatepanel). Should I write something else in order to get smarter access to the bitmap?

Protected Sub cpRubrik_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cpRubrik.Click
tbUtseenderub.ForeColor = BytFarg(e.X, e.Y)
End Sub
Protected Function BytFarg(ByVal x As Integer, ByVal y As Integer) As Color
Dim myBitmap As New Bitmap(Server.MapPath("~/img/colorpicker.bmp"))
Dim clr As Color = myBitmap.GetPixel(x, y)
Return clr
End Function

View 1 Replies

How To Assign Bitmap To Imagecontrol

Jan 7, 2010

i am trying to bind image to image control . but image is bitmap data. how can i?

View 1 Replies

Generating Bitmap Of WPF UIElement

Aug 1, 2010

I'm trying to generate a bitmap off a WPF border. The whole thing sits in a asp.net app (server side of course) running .net 4.0. The problem is, that the generated image is, well, empty. Does anyone have an idea why? Here's the code.

public static byte[] Draw(int width, int height)
{
MemoryStream memoryStream
= new MemoryStream();
Thread t = new Thread(delegate()
{
System.Windows.Controls.Border border = new System.Windows.Controls.Border()
{
Background = Brushes.Red,
BorderBrush = Brushes.Green,
CornerRadius = new System.Windows.CornerRadius(5),
Width = width,
Height = height
};
border.ApplyTemplate();
RenderTargetBitmap renderTargetBitmap =
new RenderTargetBitmap(width, height, 90, 90, PixelFormats.Pbgra32);
renderTargetBitmap.Render(border);
BitmapEncoder bitmapEncoder =
new PngBitmapEncoder();
bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
bitmapEncoder.Save(memoryStream);
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
bool success = t.Join(5000);
if (success)
return memoryStream.ToArray();
else
throw new Exception("Fail");
}

The result is quite bad, as I said the thing returns the image with the right width and height, but it's empty, so I guess I don't mess the thing up with the threading bit.

View 1 Replies

C# - Embedding A Bitmap In WebResource

Apr 6, 2010

I am generating a System.Drawing.Bitmap on the fly in an ASP.NET Custom Web Server Control, and then I want to serve this bitmap as part of the WebResource, because I do not want to save it on the hosting computer. Is there a way to instruct ASP.NET to serve the generated System.Drawing.Bitmap as part of it's WebResource? (therefore making it an "Embedded Resource")

View 1 Replies

Convert Image From URL To Bitmap

May 19, 2012

I am trying to convert a image (from url) to bitmap here the code i was using but its for using a image from your computer (file) Dim bmp As bitmap = bitmap.FromFile(TextBox1.Text) I entering a url instead of a file location but i get a URI error

View 2 Replies

Web Forms :: Display The Bitmap Image

Feb 10, 2011

i had drawed a graph by clicking a analyze button, however when i click it, it will go to a new screen. below is my coding:

[Code]....

below is the condition i want, when i click the button Analyze, the image (graph) is showed under the button with the header and template:

[Code]....

my current condition is when i click the button analyze, it will totaly display the graph only without the header and template as print screen below: how to change the coding to let the template and heaser showed together with the bar chart?

View 1 Replies

C# - Save A Bitmap As A 16 - Color Grayscale GIF Or PNG?

Jan 4, 2010

In ASP.NET C# I'm trying to save a bitmap image as an 16-color non-transparent grayscale image as either a PNG or GIF. I assume I have to create a palette and then somehow attach the palette to the image but not sure how to go about doing this. The source image is a 24-bit color Bitmap.

View 2 Replies

C# - Create Curved Text On A Bitmap?

May 10, 2010

I am currently dynamically creating a bitmap and using the graphics object from the string from the bitmap to Draw a string on it like so.

System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp);
graph.DrawString(text, font, brush, new System.Drawing.Point(0, 0));

This returns a rectangle shaped bitmap with the string written straight across from left to right. I would like to also be able to draw the string in the shape of a rainbow. How can I do this?

View 2 Replies

How To Write A Code About Get A Picture From Url And Save As Bitmap

Mar 17, 2010

I had write a code about get a picture from url and save as bitmap. However, there was a problem in HttpWebResponse. It didn't run the code start from HttpWebResponse.Then my whole website die there.

[Code]....

View 8 Replies

Web Forms :: Save Webpage As Bitmap Or Image?

Sep 20, 2010

I have to save the webpage as image in my system folder. I am saving them using stream.....but the page is not displayed as Image....It opened only through browsers.

View 2 Replies

C# - Parameter Is Not Valid Calling Bitmap.Save()?

Mar 22, 2011

This in in an ASP.NET application.

Locally, this code runs fine, but on our production server, it throws an exception of 'Parameter is not valid' when Bitmap.Save() is called.

Should I not be using System.Drawing.Bitmap because its not recommened based on this:

[URL]

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

What else could I use?

Bitmap myBitmap = new Bitmap(img);
myBitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
// get the tiff codec info
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID for the Compression parameter category
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Compression;
// create encode parameters
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
// save as a tiff
myBitmap.Save(input, myImageCodecInfo, myEncoderParameters);

View 3 Replies

Web Forms :: Writing Bitmap File On Server?

Oct 19, 2010

I'm making an application which takes image from user upload it to server and then perform any image processing like to convert to gray or invert etc.

My problem is this when i did the process on image to gray it or invert then how to write this new file on server or is there any other way so that i would be able to show this (new) image to user and make it downloadable?

View 2 Replies

Internet Explorer - Convert VML Graphic To Bitmap On The Server

Dec 14, 2010

I'm using RaphaelJS. The browser renders a chart for me (which is in VML as all my users are on IE). I want the user to be able to save this image and share it normally eg paste into an email, into powerpoint, into a document etc etc.

Problem is not many things can render VML. I can easily get the VML markup describing the image back to the server. All I want to do is convert it to some kind of more universal format eg PNG, BMP, GIFF, whatever which I can then allow the user to download. I've seen lots of people struggling with this. I would have thought the seeing as VML is Microsoft's proprietary SVG format they might have at least provided facilities within their own languages (C#,VB.net) to convert VML to bitmaps. (Incidentally I can't use PHP - I've seen a lot of people attempting to solve this with a PHP based solution)

View 1 Replies

Configuration :: Bitmap Image Saving When Running The Application On Iis Server

Apr 2, 2011

I m facing one problem which is related to Bitmap Image Actually My image is saved properly without iis server but when i run application on iis server then its give Exception "A generic error occurred in GDI+."
I m using this code-

Byte[] bytes = (Byte[])ds.Tables[0].Rows[r][1];
MemoryStream memStream = new MemoryStream();
memStream.Write(bytes, 0, bytes.Length);
System.Drawing.Bitmap origBMP = new System.Drawing.Bitmap(memStream);
System.Drawing.Bitmap newBMP = new System.Drawing.Bitmap(origBMP, 100, 150);
System.Drawing.Graphics objGra = System.Drawing.Graphics.FromImage(newBMP);
objGra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
objGra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
origBMP.Dispose();
newBMP.Save(Server.MapPath("ImageUpload\" + r + ".Jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg); //exception throw "A generic error occurred in GDI+."
newBMP.Dispose();
objGra.Dispose();

View 3 Replies

Web Forms :: Display System.Drawing.Bitmap Object On Page?

May 14, 2010

I am trying to built a WebForm with module where the user can see himself in his webcam. I am using AForge.NET framework to control the webcam.

AForge returns every frame as Bitmap object (System.Drawing.Bitmap) and now i have to display it in my WebForm. In the Windows form I would achieve it by assigning Bitmap to the PictureBox control but how do i do it in WebForm? There is only Image control avilable (System.Web.UI.WebControls.Image) which doesn`t have any .Source propery apart form .Url. How do I display Bitmap object on the page ?

View 2 Replies

C# - How To Adjust Size Of Programatically Created Bitmap To Match Text Drawn On It

May 7, 2010

I have the following .ashx page that takes some query string parameters and returns a bitmap with the specified text written on it. The problem I have is that I am currently just manually setting the initial size of the bitmap at 100 X 100 when what I really want is to have the bitmap be just big enough to include all the text that was written to it. How can I do this?

[Code]....

View 1 Replies

WebMatrix :: Get An Error Message "filetype Blocked".The File Is Called Test.jpg And Is Drawn To The Screen As A Bitmap?

Oct 25, 2010

I am working on a website that draws fractals on the screen. It was my intention that with a right mouse click the picture could be saved to the visitor's computer. But that I get an error message "filetype blocked".The file is called test.jpg and is drawn to the screen as a bitmap. Could anybody tell me how to 'unblock' the right mouse click so that a visitor can save a picture he or she likes?Maybe it would be possible to let people download the image? But how would that work?

View 3 Replies

Web Forms :: Use System.Drawing.Bitmap Class Into Other Class?

Oct 5, 2010

How can I to use System.Drawing.Bitmap class into athoer class?

using System.Data;
using System.Collections;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace University
{
public class Class1
{
System.Drawing.Bitmap BMP=new System.Drawing .Bitmap();
}
}

when I use System.Drawing.Bitmap gives error this class does not exists

View 2 Replies

C# - Auto Generate Javascript To Update Client Html Compared To Previous Html?

Jan 16, 2010

do you think it would be difficult to write a framework where mvc compares last html it output to the current html we want to output, and instead of sending the entire html, figure out what has changed and generate js code that will do the updating as compared to previous html? (presuming nothing was manually changed on the client using js).

View 2 Replies

Forms Data Controls :: Repeater ItemTemplate - If Eval(field)=0 Then HTML Else HTML

Feb 20, 2010

The following seems reasonable, but it returns an error:

<asp:Repeater ID="RepeaterF" runat="server" DataSourceID="DSF" >
<ItemTemplate>
<%
If Eval("Item_Batch") = 0 Then
%><tr><td></td><td colspan="2"></td><td></td></tr><%
Else %>........

Error: "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

I am finding it difficult to accept that the whole Repeater approach has any benefits over just creating a loop in code, iterating through a recordset, and building a html table into a variable, then dumping it to the page. This repeater is spawning pages of code and objects, and surely this is all using up server resources.

View 2 Replies

MVC :: How To Pass A Value Form ActionResult To Html.textbox Or Html.TextBoxFor In View

Mar 18, 2010

how can i passing a value form ActionResult to html.textbox or Html.TextBoxFor in View

View 2 Replies

C# - Cutting HTML String Into Separate Lines Without Breaking HTML Tags

Oct 24, 2010

I have to break a HTML content string in to multiple lines. And each line should have some fixed characters, 50 or 60 Also I don't want to break the word..or html tags...

ex : <p>Email: <a href="mailto:someone@gmail.com">someone@gmail.com</a></p>
<p><em>"Text goes <font color=red>Hello world</font> Text goes here and Text goes here Text goes here 1976."</em> </p>

How can I acheive this in C#?

View 1 Replies

MVC :: The Name 'Html' Does Not Exist In The Current Context / Not Recongnizing The Html And Model Classes?

Apr 30, 2010

I am working on an ASP.NET MVC 2 project with VS 2010 and out of nothing I get the following errors on my views:

The name 'Html' does not exist in the current context

The name 'Model' does not exist in the current context

It is like it is not recongnizing the MVC Html and Model classes.

I have System.Web.Mvc on my references and on Web.Config I have:

[Code]....

View 2 Replies

Web Forms :: Catch The HTML Button Click Event On A Class File Including HTML Text Box Value

Sep 24, 2010

I want to catch the html button click event on a class file including html text box value..

[code]....

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved