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


Similar Messages:

C# - Creating And Save An Image From A Byte[] Causes Parameter Is Not Valid Exception?

Nov 18, 2010

I have implemented the following functionality that connects to webservice and downloads a favicon from a given site and saves it to a byte[] which I store in our database. I now want to set it up so that it saves the icon to the disk. However I am getting a "Parameter is not valid" when I try and create the image from the byte[].My code is as follows..

stream.Write(imageByteArray, 0, imageByteArray.Length);
Image i = Image.FromStream(stream); // EXCEPTION HAPPENS HERE.
i.Save(@"C: mp" + filename + ".ico");

The exception occurs on the middle line. This code works perfectly 9 times out of ten, but for some favicons, even thought the icon is a valid image (or at least it appears to be and it shows in the browser when point at it) I get this exception. Does anyone have any ideas? I am pulling my hair out here!

View 2 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

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

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

DataSource Controls :: Parameter Is Not Valid?

Apr 13, 2010

I'm trying to get image from database into picturebox

pictureBox1.Image = Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i].ItemArray[0]));

But I am getting error:

parameter is not valid

View 1 Replies

Web Forms :: Getting Image To Display - Parameter Is Not Valid?

Apr 26, 2010

I am trying to display an image from database, and I keep ending up with an error Parameter is not valid. Bitmap bm2 = new Bitmap(targetW, targetH);

I have tried different ways but I can't get it to work (as you can see in my commented code). I am having trouble on the saving it to the database process, displaying it isn't a problem (when I had valid images)

[Code]....

View 3 Replies

Visual Studio :: System.ArgumentException - Parameter Is Not Valid

Jul 22, 2010

I get this Microsoft .NET Framework start up error. when i try to run a window project.

i am working on visual studio2005 (.NET FRAMEWORK2.0).

i am working on win 7 machine & i am not able to edit machine.config file.coz it is read only type.

below is the error ....

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

Exception Text

System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(String filename)
at HumanHistology.frmquiz1.FillOptions()
at HumanHistology.frmquiz1.btnnext_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Loaded Assemblies

mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase:
file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll.........

View 3 Replies

C# - Parameter Is Not Valid Exception When Saving Image In Winform?

Nov 22, 2010

I am getting a parameter is not valid exception..While saving the image

Here is my code to save the image

if (!File.Exists(pictureBox1.Tag.ToString()))
{
Image image = pictureBox1.Image;
image.Save(pictureBox1.Tag.ToString(), ImageFormat.Jpeg);
}
else
{
string delStr = pictureBox1.Tag.ToString();
pictureBox1.Image.Dispose();
File.Delete(delStr);
Image image = pictureBox1.Image;
image.Save(delStr, ImageFormat.Jpeg);
pictureBox1.Image = Image.FromFile(delStr);
}

View 2 Replies

Nullable DateTime Parameter Never Bound When Calling Action

Sep 20, 2010

I have the following function signuture:

public JsonResult PopulateGrid(int page, Guid? accountId, Guid? systemUserId, Guid? branchId, DateTime? fromDate, DateTime? toDate, HomeVisitType? homeVisitType)

Every single parameter is bound just fine except toDate which turns out to be always null. When inspecting the Request.QueryString["toDate"] it retrives the right value which is 30/09/2010. It seems that DateTime expects another format when binding.
What is the right format?

View 1 Replies

Web Forms :: How To Pass Parameter To C# Method Calling In Javascript

Feb 4, 2010

How to pass parameter to c# method calling in javascript.

My code is like this .

objTotalInclusive.value=TotalAmtInclu.toFixed(2);
objRoundOff.value= Math.round(TotalAmtInclu);
var wordsnum= objRoundOff.value;
var objwordstonum =document.getElementById('<%=lblNumSpelling.ClientID%>');
var objwords = '<%NumberToSpelling(''+ wordsnum+'')%>';
objwordstonum.value= objwords;

View 6 Replies

JQuery :: Calling PageMethod With Complex Type Parameter?

Mar 17, 2011

I have a page method which take in a complex parameter how can i call this page method using jquery.

This is my page method

[Code]....

and these are my types

[Code]....

View 2 Replies

Web Forms :: Calling Page - Pass Parameter In Url Query String?

Apr 14, 2010

We are using a asp.net page to submit data to server. what we do is we will pass as parameter in url Query string) and in page load we take that values and submitting to database I have these following doubt

1, What is the default event happening while we call a ASP.NET page is it a POST or GET? We tried to call this url from a mobile application, it is not happening , we are not getting any error also in the mobile application.

2, IF we are calling the url to submit data from mobile applications which one we have to use (GET or POST)

3, IF we are calling this url from an application running in PC to submit which one we have to use ?

View 3 Replies

DataSource Controls :: Calling Stored Procedure With Hierarchyid Parameter?

Apr 3, 2010

How do you call a stored procedure using C# .NET 3.5 that contains a parameter that is of type hierarchyid in SQL Server 2008?

A basic outline of my current code is as follows:

SqlConnection conn =
new
SqlConnection(DatabaseConnectionString);
SqlCommand StoredProcedureCommand =
new
SqlCommand("AddUser", conn);
StoredProcedureCommand.CommandType =CommandType.StoredProcedure;
SqlParameter ParamUsername = StoredProcedureCommand.Parameters.Add("@Username",
SqlDbType.NVarChar);
SqlParameter ParamPassword = StoredProcedureCommand.Parameters.Add("@Password",
SqlDbType.NVarChar);
SqlParameter ParamMasterNode = StoredProcedureCommand.Parameters.Add("@MasterNode",
SqlDbType.Text);
// HierarchyID type
ParamDynamboUsername.Value = Username;
ParamPassword.Value = Password;
ParamMasterNode.Value = "/";
conn.Open();
StoredProcedureCommand.ExecuteNonQuery();
conn.Close();

View 2 Replies

AJAX :: Web Service Method With Parameter Isn't Calling With Autocomplete Text Box Extender

Feb 22, 2011

web service method(getMainHeads) with parameter is not calling with auto complete text box extender(same method with out parameter is calling fine). My Service is

[System.Web.Script.Services.
ScriptService]
public
class
InvService : System.Web.Services.WebService
{
ItemMainHeadMsts objItemMainHeadMsts;
DatabaseHelper objDataHelper;
[WebMethod]
public
string[] GetMainHeads(string value)
{
List<string>
oList = new
List<string
>();
objItemMainHeadMsts =
new
ItemMainHeadMsts
();
objDataHelper =
new
DatabaseHelper
();
objItemMainHeadMsts =
ItemMainHeadMstBase.SelectByFieldAuto("IMHDesc"
, value);
foreach (ItemMainHeadMst
mainHead in
objItemMainHeadMsts)
{
oList.Add(mainHead.IMHDesc);
}
return
oList.ToArray();..........................

View 4 Replies

Web Forms :: Error: "Specified Argument Was Out Of The Range Of Valid Values. Parameter Name: I"

Feb 28, 2011

I am working on developing web application for user to upload their files using VB.NET.The problem is,when user browse and upload the file they got an error saying that : Specified argument was out of the range of valid values. Parameter name: i Here is a piece of codes i currently used :

[Code]....

When i debug the program,it stop at line :

[Code]....

View 1 Replies

C# - "Parameter Is Not Valid" Exception From System.Drawing.Image.FromStream() Method?

Aug 27, 2010

I got a hard time with the Image.FromStream method in my website. The code below works perfect on my computer. But when I uploaded it to the test server, it always gives me "Parameter not valid" exception.

if (!afuImageFile.IsUploading && afuImageFile.HasFile)
{
System.Drawing.Image imgFile = System.Drawing.Image.FromStream(afuImageFile.FileContent);
}

the afuImageFile is an AsynFileUploader control in Ajax Tool Kits. afuImageFile.FileContent is a HttpInputStream.

View 1 Replies

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

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# - 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







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