473,810 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert, Rotate And Convert Again Error

Tyler Wiebe
66 New Member
I'm trying to rotate a System.Drawing. Icon, but first I need to convert it to a System.Drawing. Bitmap, then rotate it, and then convert it back to a System.Drawing. Icon, which is being looped, which works fine... for 2:34 minutes.

I'm using this to convert the System.Drawing. Icon to a System.Drawing. Bitmap
Expand|Select|Wrap|Line Numbers
  1.         public static System.Drawing.Bitmap ToBitmap(System.Drawing.Icon Icon)
  2.         {
  3.             System.IO.MemoryStream IconStream = new System.IO.MemoryStream();
  4.             Icon.Save(IconStream);
  5.  
  6.             byte[] BitmapBytes = IconStream.ToArray();
  7.  
  8.             System.IO.MemoryStream BitmapStream = new System.IO.MemoryStream(BitmapBytes, 0, BitmapBytes.Length);
  9.             BitmapStream.Write(BitmapBytes, 0, BitmapBytes.Length);
  10.  
  11.             return new System.Drawing.Bitmap(System.Drawing.Bitmap.FromStream(BitmapStream));
  12.         }
  13.  
The reason I'm doing this is because for some reason, Icon.ToBitmap() , turns all transparency to white, my method how ever does not.

But my method also causes an error after 2:34 minutes, which is on the return, which says, "Parameter is not valid."

And besides that, from what I'm aware, there's no other way of doing this, and this also causes another error after 2:34 minutes.
Expand|Select|Wrap|Line Numbers
  1.         public static System.Drawing.Icon ToIcon(System.Drawing.Bitmap Bitmap)
  2.         {
  3.             return System.Drawing.Icon.FromHandle(Bitmap.GetHicon());
  4.         }
  5.  
After 2:34 minutes, I also get the error, "A generic error occurred in GDI+."

Most of the time the GDI+ error occurs, but sometimes the other one occurs, and I'm not sure what to do about this.

Any help would really be appreciated.
Apr 22 '12 #1
2 2228
RhysW
70 New Member
http://www.dreamincode.net/forums/to...space-part-ii/ this has got everything and more that you could ever want to know about the system.drawing namespace, complete with demonstrations, for example here is the code used to rotate an image, it is different from yours and therefore may give you different results, (it still requires you to turn it into a bitmap and back but you seem to be fine with doing that.) let me know if this code works better for you!

Expand|Select|Wrap|Line Numbers
  1. public static Image RotateImage(Image img, float rotationAngle)
  2. {
  3.     //create an empty Bitmap image
  4.     Bitmap bmp = new Bitmap(img.Width, img.Height);
  5.     //turn the Bitmap into a Graphics object
  6.     Graphics gfx = Graphics.FromImage(bmp);
  7.     //now we set the rotation point to the center of our image
  8.     gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
  9.     //now rotate the image
  10.     gfx.RotateTransform(rotationAngle);
  11.     gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
  12.     //set the InterpolationMode to HighQualityBicubic so to ensure a high
  13.     //quality image once it is transformed to the specified size
  14.     gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
  15.     //now draw our new image onto the graphics object
  16.     gfx.DrawImage(img, new Point(0, 0));
  17.     //dispose of our Graphics object
  18.     gfx.Dispose();
  19.     //return the image
  20.     return bmp;
  21. }
  22.  
Apr 24 '12 #2
Tyler Wiebe
66 New Member
I should have mentioned that the code I'm using in to rotate the image between conversion is exactly that.

I'm having no problem converting the icon to a bitmap, rotating it 15 degrees, and then converting it back to an icon every 40 milliseconds for 2:34 minutes, but after that I get one of those two errors, which from the fact that I've rotated it many times during a time span of 2:34 minutes, I don't understand what is causing this error.
Apr 24 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5637
by: Bartosz Majewski | last post by:
Hello, I have a question. Is there any possibility to compile MS Access database (e.g. *.mdb file) to standalone, executable application? I'd like to use such database application on a computer where Access is not installed. I know, that it's possible to write such kind of app in Visual Basic, but as far as I know, there cannot be any relations in that program (and that is why that solution is not, what I mean). I would be greateful for...
7
3013
by: Jos De Laender | last post by:
Following simple program : #include <stdio.h> char *Convert(int Arg) { static char Buffer; printf("Convert called for %d\n",Arg); sprintf(Buffer,"%d",Arg); printf("Convert about returning %s\n",Buffer); return Buffer;
1
2204
by: Andreas Klemt | last post by:
Hello, I have this session("myNumber") = 888 Dim intNumber As Integer a) intNumber = session("myNumber") b) intNumber = Convert.ToInt32(session("myNumber"))
2
1576
by: Alex Nitulescu | last post by:
Hi. I have created a web-based "file manager", for remote-administration of a web-site. It works okay. The "main" form in the "file manager" is BrowseFiles.aspx. I can edit the text files (among which the "js" files) by clicking on an achor which redirects me to "edit.aspx". Once in "edit.aspx", after I view a ".js" file, for instance, I click on the button "Return to file manager". The code in the command "Return to file manager" is...
3
2559
by: byrd48 | last post by:
Hi, I am developing a web site which allows users to upload and share photos. I have a datalist which lists the photos and has the usual edit, update commands. Within the edititemtemplate, I have links to allow the user to rotate the photo 90 degrees left or right. After I rebind the datalist,the photo is not rotated on the web page, although it correctly rotated on the server. If I click refresh, it updates, but calling refresh causes...
4
1895
by: Mike Collins | last post by:
This worked in the command window while in debug mode ?table.Rows.ItemArray.ToString() "f0165f94-648f-4997-b578-11d89c8b1f61" But gives the error below when I compile. Cannot implicitly convert type 'string' to 'int' and the word ColumnName is underlined.
7
3412
by: WT | last post by:
Hello, VS2005 with SP1. I succefully coverted my Web Site Project to Web Application project, but, for an aspx class, the manuel (by right clic menu) 'Covert to Web Application, gives the error. 'Could not parse the file app_support\myfile.aspx' and no designer.cs file is created. It is working for all other aspx files in this app_support folder ?
0
1325
by: IanJSparks | last post by:
I've been doing some image rotation with PIL and comparing the images with imagemagick's convert -rotate output. Imagemagick uses an RBS / Paeth rotation algorithm that appears to give better results than PIL's rotate method. However, I love PIL and don't want to have to shell out to imagemagick or use it's python bindings if I can stay with my beloved Python Imaging Library.
0
5742
by: kronus | last post by:
Hi everyone, Please tell me what I am doing wrong: I have an xml data coming to my Air application that looks something like this: <project name="Sales Demos" path="/Company Home/Client Spaces/Sales Demos" type="{http://www.myCo.org/model/content/1.0}folder" id="71f36dcd-b59b-11dd-8205-5992b4466fe5" modified="Nov 18, 2008 3:51:20 PM" size="" icon32="/images/icons/default.gif" viewurl=""/> <project name="Something else" ... etc... />
5
3745
by: furqi | last post by:
hi every body i write a code in c sharp in which i have made a base class and make an event there.Then i make a derived class and made an other event in that class. Now what i wanna do is that i wanna invoke in derived class method the base class event but i am facing an error there i am unable find the solution.canaby body tell me the solution.following is the code. using System; using System.Collections.Generic; using System.Linq;...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.