.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Getting generic GDI error when trying to save resized image

Posted By:      Posted Date: August 23, 2010    Points: 0   Category :ASP.Net
Getting following error:A generic error occurred in GDI+.
Any help is appreciated.
Public Sub SaveImageFile(ByVal sourceImage As Bitmap, ByVal saveImagePath As [String], ByVal maxImageWidth As Integer)
            ' Resize if source image width is greater than the max:

            If sourceImage.Width > maxImageWidth Then
                Dim bmp As Bitmap = TryCast(sourceImage, Bitmap)
                Dim newImageHeight As Integer = CInt(Math.Truncate(sourceImage.Height * (CSng(maxImageWidth) / CSng(sourceImage.Width))))
                Dim gr As Graphics = Graphics.FromImage(bmp)

                Dim bmpnew As New Bitmap(maxImageWidth, newImageHeight)
                gr.InterpolationMode = InterpolationMode.HighQualityBicubic

                gr.DrawImage(bmpnew, 0, 0, maxImageWidth, newImageHeight)

                'code to manipulate bmpNew goes here.



View Complete Post

More Related Resource Links

image.save not saving images


I have a piece of code that writes string into an image and save it. It works on one of my site and but not the other. The image.save is not working. If this is a permission problem, which account should I change? I use win server 2003 and IIS 6, and have given ASPNET, NETWORK SERVICE, and anonymous user write access.

A generic error occurred in GDI+.



I'm getting this error on the yellow screen and I have no idea what to do with it, or where to start:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +377630
NopSolutions.NopCommerce.BusinessLogic.Media.PictureManager.GetPictureUrl(Picture picture, Int32 targetSize, Boolean showDefaultPicture) in F:\Temp\Test\nopCommerce 1.60\Libraries\Nop.BusinessLogic\Media\PictureManager.cs:396
NopSolutions.NopCommerce.BusinessLogic.Media.PictureManager.GetPictureUrl(Picture picture, Int32 targetSize) in F:\Temp\Test\nopCommerce 1.60\Libraries\Nop.BusinessLogic\Media\PictureManager.cs:180
NopSolutions.NopCommerce.Web.Administration.Modules.CategoryInfoControl.BindData() in F:\Temp\Test\nopCommerce 1.60\NopCommerceStore\Administration\Modules\CategoryInfo.ascx.cs:63
NopSolutions.NopCommerce.Web.Administration.Modules.CategoryInfoControl.Page_Load(Object sender, EventArgs e) in F:\Temp\Test\nopCommerce 1.60\NopCommerceStore\Administration\Modules\CategoryInfo.ascx.cs:99
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

A generic error occurred in GDI+


I am getting this error at this line in my code: ImgThnail.Save(ThumbnailPath, Img.RawFormat);

Here is the entire code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

    public static class Thumb2
        public static string createThumb(this HttpServerUtility srv, string endPath, string tempPath, int relSize)

            string ThumbnailPath = srv.MapPath("~\\Thumb\\" + endPath);
            string dimensions;
            using (System.Drawing.Image Img = System.Drawing.Image.FromFile(srv.MapPath("~\\" + tempPath))) 
                Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, relSize);
                dimensions = Img.Width.ToString() + " x " + Img.Height.ToString();
                using (System.Drawing.Image ImgThnail = new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
                    ImgThnail.Save(ThumbnailPath, Img.RawFormat);
            return dimensions;
        private static Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
            Size NewSize;
            double tempval;
            bool landscape;

Insert image into Infopath form and save to SharePoint as PDF file


I have an InfoPath web-enabled form in MOSS 2007, that is integrated with a K2 blackpoint process for an approval workflow.

Once the form (a Purchase Order request form) has been approved in the K2 workflow process, I switch the form view to a "print-friendly" view for the requestor to view from the browser.  However, now I need to go one step further with this scenario:

1) I need to somehow insert/embed an image with the scanned-in signature of the approver (likely stored in a SP doc library) at the signature line section of my form.  Also, what are the security requirements for storing such images, but not granting all users access to these (e.g. only services accounts that need to access this for embedding into the form, etc.)?

2) Then I need to convert this final "print-friendly" view of the form (with the signature image) to a PDF document so that I can store it in SharePoint (and email it to the requestor using K2's email event capabilities).

Can anyone help me with a solution to both of these requirement, or point me to some resources for this (even 3rd party components are open-game).



AsyncFileUpload: Throw Error on image size


I have an AsyncFilUpload that is used to upload  to my site. On the server side I have code that checks the width and height of the image and will only save the image if it is within the limits buit I can't figure out how to get the AsyncFileUpload control to show an error when this happens. Can anyone give me any pointers?


Error: Do you want to save this file, or find a program online to open it?



I am relatively new to MVC , i am getting the following error when i try to browse to a page in which i have used usercontrol and within the usercontrol i have a simple grid.

Error: Do you want to save this file, or find a program online to open it?

I am returning the data from the controller like this

 var jsonData = new
                    total = 1,
                    page = 1,
                    records = myRequests.Count,
                    rows = new[]{myRequests.ToArray()                 

Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+



This is what I'm trying to do when I get the error on the server (it works on my local machine):

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 

Response.ContentType = "image/bmp";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);

I don't think it can be a permissions problem because this works on the server:

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);

Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

So how do I get this to work for a bitmap?


"Save as image" available programatically?

Hi,With the rehosted designer it is possible to right click in the design area and choose to save the workflow as an image. This is cool functionality and was wondering if it was possible to call this programatically? This would then allow me to show an image of what the workflow looks like without having to load up the full designer.Does anyone know if this is possible or how it can be done.ThanksMatt

Why Image.save creates a black image

Hello, I am trying to create a screenshot, here is the code, it creates a complete black image.Thanks for any help. Public Function CaptureWindow(ByVal handle As IntPtr) As Image               ' get te hDC of the target window               Dim hdcSrc As IntPtr = User32.GetWindowDC(handle)               ' get the size               Dim windowRect As New User32.RECT()               User32.GetWindowRect(handle, windowRect)               Dim width As Integer = windowRect.right - windowRect.left               Dim height As Integer = windowRect.bottom - windowRect.top               ' create a device c

A generic error occurred in GDI+. I am not sure what I am doing wrong please help!!

hello... Sorry but I get some error when I try to save an image.Here is my code If Not System.IO.Directory.Exists(DirectoryPath) Then System.IO.Directory.CreateDirectory(DirectoryPath) End If Dim FilePathName As String = DirectoryPath & "\avatar.jpg" Dim fs As New FileStream(FilePathName, FileMode.Create, FileAccess.Write) Using avatarMs As New MemoryStream(ImageBytes, 0, ImageBytes.Length) avatarMs.Write(ImageBytes, 0, ImageBytes.Length) Dim image As Image = image.FromStream(avatarMs, True)  image.Save(DirectoryPath, System.Drawing.Imaging.ImageFormat.Jpeg)'<--generic error occurred in gdi+ error appeared here End Using control.ImageUrl = DirectoryPathbasically what this code is doing is loading an an array of bytes into the memorystream(avatarMS) then converting the memory stream into an image(image) then saving the image into a folder(DirectoryPath) then displaying the image into an image control in client side... I know I am missing something here... but I don't really know what. I am not very sound in this language so if there is anything I missed out, please ask.Thanks in advanceRegards, Zephere

Visual Studio Extension: Save UML diagram as image

I am auditing one big legacy application. I use Visual Studio 2010 modeling projects to visualize the design of this legacy application. When I wanted to get my UML diagrams to image files so I can insert them to documents I found no option for it. As it turned out we have to write extension for modeling projects and deploy it as Visual Studio 2010 extension. Here is the installer and source package of my UML.SaveAsImage extension. UML.SaveAsImage.zip VS2010 solution | 48KB UML.SaveAsImage.Install.zip VSIX insaller | 4KB I still cannot believe that we need to write extensions to get our UML diagrams to image files but okay, it's done now and let's say - problem is solved. At least this one. In my work I used code example by Cameron Skinner. He has very good blog posting titled as Save a diagram to Image File. Here are steps how I wrote this extension. 1. Create new Layer Designer Command Extension project As a first thing you should create layer designer command extension project. If you don't have support for modeling projects you should take more powerful edition of Visual Studio 2010. Name it your project as you like and click OK. 2. Add functionality to Command class You can find Command class from your new project. This class is created by default. Here is the modified code from Cameron Ski

A generic error occurred in GDI+

Im trying to save an image on my hosting server. Locally everything works fine, but on the hosting server I get the error: "A generic error occurred in GDI+"I've already looked at this post: http://forums.asp.net/t/975883.aspxBut im unsure how to go about changing my current code below:    Public Shared Function SaveJpeg(ByVal path As String, ByVal img As Image, ByVal quality As Long) As Boolean        If ((quality < 0) OrElse (quality > 100)) Then            Return False            Throw New ArgumentOutOfRangeException("quality must be between 0 and 100.")        End If        ' Encoder parameter for image quality        Dim qualityParam As New EncoderParameter(Encoder.Quality, quality)        ' Jpeg image codec        Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")        Dim encoderParams As New EncoderParameters(1)        encoderParams.Param(0) = qualityParam        Try  

image error

private void dataGridView2_SelectionChanged_1(object sender, EventArgs e) { if (dataGridView2.SelectedRows.Count > 0) { pictureBox1.ImageLocation = dataGridView2.SelectedRows[0].Cells[12].Value.ToString(); this.Refresh(); imgOriginal = pictureBox1.ImageLocation; //cannot implicitly convert type string to system.image } } private Image imgOriginal; private void trackBar1_Scroll(object sender, EventArgs e) { if (trackBar1.Value > 0) { pictureBox1.Image = null; pictureBox1.Image = PictureBoxZoom(imgOriginal,new Size(trackBar1.Value, trackBar1.Value)); } } error: can not implicilty convert type string to system.drawing.image

Getting error that the converter failed to save the file

From a document library I click on "Edit in Microsoft Excel (or Word) and the application is not open I get the error "The converter failed to to save the file".  It never opens the application and I'm returned to the document library.  If I already have the application it doesn't generate the error.  I'm running Office 2007

How to : Generic error handling function. Passing GridViewUpdatedEventArgs as EventArgs

Hi, I want to build a generic error handling function for handling inseted, updated, deleted events from formview, gridview and detail view. I am still a bit new to C# so I have encoutered a simple problem that I cannot resolve and cannot find an answer while searching google.Right now I handle error with validator for generic validation but I need to catch BLL error.I have different event handler for the different type of event : protected void FormView_AjoutCompte_ItemInserted(object sender, FormViewInsertedEventArgs e) { if (e.Exception != null) { Afficher_Erreur(e.Exception); e.ExceptionHandled = true; } } protected void GridView_ListeUtilisateurs_RowUpdated(object sender, GridViewUpdatedEventArgs e) { if (e.Exception != null) { Afficher_Erreur(e.Exception); e.ExceptionHandled = true; } } protected void GridView_ListeUtilisateurs_RowDeleted(object sender, GridViewDeletedEventArgs e) { if (e.Exception != null) { Afficher_Erreur(e.Exception); e.ExceptionHandled = true; } } I want to create a generic function that will handle them all, a function such as : private void GestionDerreur(EventArgs e) { if (e.Exception != null) { Afficher_Erreur(e.Exception); e.Exc

Winnovative:Could not save image. Parameter is not valid.

while running website,the image get extracted from pdf document but still an exception named pdfimgextractexception appears at the end of an application.please give me the solution regarding this problem. code as follows: pdfImgExtractor.ExtractImages(srcPdfFile,true); which calls an eventhandler: pdfImgExtractor.ImageExtractedEvent += new ImageExtractedEventHandler(pcmd.pdfImgExtractor_ImageExtractedEvent); where the definition is: {   try { System.Drawing.     ographics = ographics.DrawImage(extractedBitmap, extractedBitmap.Dispose(); extractedBitmap = obitmap;     ographics.DrawString( ographics.Dispose(); ofont.Dispose(); oBrush.Dispose(); extractedBitmap.Save( extractedBitmap.Dispose(); }   {   }   Bitmap extractedBitmap = args.ExtractedBitmap;Graphics ographics;Bitmap obitmap = new Bitmap(extractedBitmap.Width, extractedBitmap.Height);Graphics.FromImage(obitmap);new Rectangle(0, 0, obitmap.Width, obitmap.Height), 0, 0, extractedBitmap.Width, extractedBitmap.Height, GraphicsUnit.Pixel);SolidBrush oBrush = new SolidBrush(Color.Black);Font ofont = new Font("Arial", 8);"Some text to write", ofont, oBrush, 10, 10);"D:\\example.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);catch (Exception err)HttpContext.Current.Response.Write(err.Message); } thanks in advance.

.NET Framework 4 Installation error - Generic Trust Failure

I tried to install .NET Framework 4 on Windows Server 2003, but got this error message "Generic trust failure".Part of the log:Action: Downloading and/or Verifying ItemsC:\e005b9f00558a52d0c\Windows6.0-KB956250-v6001-x86.msu: Verifying signature for Windows6.0-KB956250-v6001-x86.msuC:\e005b9f00558a52d0c\Windows6.0-KB956250-v6001-x86.msu Signature verified successfully for Windows6.0-KB956250-v6001-x86.msuC:\e005b9f00558a52d0c\Windows6.1-KB958488-v6001-x86.msu: Verifying signature for Windows6.1-KB958488-v6001-x86.msuC:\e005b9f00558a52d0c\Windows6.1-KB958488-v6001-x86.msu Signature verified successfully for Windows6.1-KB958488-v6001-x86.msuC:\e005b9f00558a52d0c\netfx_Core.mzz: Verifying signature for netfx_Core.mzzC:\e005b9f00558a52d0c\netfx_Core.mzz Signature verified successfully for netfx_Core.mzzC:\e005b9f00558a52d0c\netfx_Core_x86.msi: Verifying signature for netfx_Core_x86.msiPossible transient lock. WinVerifyTrust failed with error: 2148204800Possible transient lock. WinVerifyTrust failed with error: 2148204800C:\e005b9f00558a52d0c\netfx_Core_x86.msi - Signature verification for file netfx_Core_x86.msi (C:\e005b9f00558a52d0c\netfx_Core_x86.msi) failed with error 0x800b0100 (No signature was present in the subject.)C:\e005b9f00558a52d0c\netfx_Core_x86.msi Signature could not be verified for netfx_Core_x86.msiNo FileHash provided. Cannot perform FileHash veri
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend