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.
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:
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 = myEncoderParameter; // save as a tiff myBitmap.Save(input, myImageCodecInfo, myEncoderParameters);
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
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
If i want to create a web site that take your picture and share it for your friends, what the best way to save the picture files on server? What the way is safer for the picture files? What the way has the best performance?
I am uploading images in c# windows application. I am uploading the images folder wise. In one folder there are 200 to 3000 images. My one images size is about 3.10 MB to 6.2 MB. Its dimensions are 3008 x 1960, 1960 , 4000 x 2600. 6000 x 4000 . while uploading i am reducing the size of image to 400 x 266 or 266 x 400 depending on the height and width of image. but still my image size is about 227 KB. Now i want to reduce the image resolution to decrease the image size.
i help save image as picture in sql databases for consumer profile now i possess a site that sow consumer profile facts an im this site i possess a picture manage to display consumer avatar with. in code at the rear of with Userprofile.Avatar code i obtained the picture as byte
I am trying to do some code where a user will be able to upload a .JPG picture from the users computer. I have put the controls and also written the C# code wich in my eyes seems to be correct. What happens in the code is that the uploaded picture will replace the existing "TopHeader.JPG" picture.
However when I run the code after I have choosen a .JPG picture from the desktop on my computer. Nothing happens except of a postback of the page.
I wonder what I can be missing out in order to make this work. (I attach both the HTML code and the C# code, I will be happy to know what I could be missing out)
how can I create stored procedure and write my select statement in it, I know how to create dataset then put type stored procedure and assign it to the sp ... what I want is writing my sp... how can I make it ?
check the following code, this is what I want to write put I don't know where or how !
I ve an application dat am working on. The section of the upload picture works perfectly on the development environment and also on a test server but the issue comes up when it was hosted life. I started geting an error dat says picture could not be attached. I ve a folder cald Passport and dis ve been working for me on befor now but i dont now the reason y its not working now.
I have a code which I repeat over and over so I am thinking to write subroutine. Not sure if there are functions in C#. Could you advise how to pass arguments to it. An example of add two numbers would be great.