Click here to Skip to main content
15,913,941 members
Home / Discussions / C#
   

C#

 
AnswerRe: Rounding numbers Pin
J4amieC8-Dec-06 1:08
J4amieC8-Dec-06 1:08 
GeneralRe: Rounding numbers Pin
matthias s.8-Dec-06 1:13
matthias s.8-Dec-06 1:13 
AnswerRe: Rounding numbers Pin
ednrgc8-Dec-06 3:23
ednrgc8-Dec-06 3:23 
QuestionSafely create System.Drawing.Bitmap from managed int[] Pin
N-O-R-B-E-R-T8-Dec-06 0:59
N-O-R-B-E-R-T8-Dec-06 0:59 
AnswerRe: Safely create System.Drawing.Bitmap from managed int[] Pin
Luc Pattyn8-Dec-06 1:46
sitebuilderLuc Pattyn8-Dec-06 1:46 
GeneralRe: Safely create System.Drawing.Bitmap from managed int[] Pin
N-O-R-B-E-R-T9-Dec-06 2:22
N-O-R-B-E-R-T9-Dec-06 2:22 
GeneralRe: Safely create System.Drawing.Bitmap from managed int[] Pin
Luc Pattyn9-Dec-06 9:20
sitebuilderLuc Pattyn9-Dec-06 9:20 
GeneralRe: Safely create System.Drawing.Bitmap from managed int[] Pin
N-O-R-B-E-R-T9-Dec-06 12:44
N-O-R-B-E-R-T9-Dec-06 12:44 
No it wasn't. I knew that article, but I didn't get that code working. Also the ImageConverter which is mentioned in the articles message board didn't work for me.

My code, as nasty as it is by now looks like this:

using System.Runtime.InteropServices;
using System.Drawing;

...

public void saveImage(String filename)
        {
            List<byte> byteList = new List<byte>();
            lock (this)
            {
                foreach (int color in m_data)
                {
                    byteList.AddRange(System.BitConverter.GetBytes(color));
                }
            }

            byte[] byteData = byteList.ToArray();
            GCHandle handle = GCHandle.Alloc(byteData); ;
            try
            {
                IntPtr imgDataPtr = Marshal.UnsafeAddrOfPinnedArrayElement(byteData, 0);
                if(imgDataPtr != IntPtr.Zero)
                {
                    Bitmap img = new Bitmap(this.Height, this.Width, byteData.Length, PixelFormat.Format32bppArgb, imgDataPtr);
                    Random rnd = new Random();
                    img.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff);
                }
                else
                {
                    System.Diagnostics.Debugger.Break();
                }
            }
            catch(Exception e)
            {
                System.Diagnostics.Debugger.Break();
            }
            finally
            {
                handle.Free();
            }
        }


The creation of the Bitmap always threw ArgumentExceptions, when the PixelFormat is anything else than Format32bppArgb. It took me quite a time to figure out, that PixelFormat was the parameter which caused the problem, since I don't see any obvious differences between Format32bppArgb and Canonical which are both 32 Bits / pixel and should at maximum cause some mixed up channels when stated wrong.

So maybe I'd get the Bitmap creation running with one of the linked examples above, if I check again for the correct PixelFormat, but by now I think I better use that maybe unnecessarily complicated version you helped me to figure out.

If I get a shorter and less complicated version running, I'll post it here.

Norbert
QuestionForm Layout SDI or MDI Pin
h@s@n8-Dec-06 0:26
h@s@n8-Dec-06 0:26 
AnswerRe: Form Layout SDI or MDI Pin
Bhupi Bhai8-Dec-06 0:56
Bhupi Bhai8-Dec-06 0:56 
AnswerRe: Form Layout SDI or MDI Pin
Pete O'Hanlon8-Dec-06 1:20
mvePete O'Hanlon8-Dec-06 1:20 
GeneralRe: Form Layout SDI or MDI Pin
h@s@n8-Dec-06 2:40
h@s@n8-Dec-06 2:40 
GeneralRe: Form Layout SDI or MDI Pin
Pete O'Hanlon8-Dec-06 2:58
mvePete O'Hanlon8-Dec-06 2:58 
GeneralRe: Form Layout SDI or MDI Pin
h@s@n8-Dec-06 5:21
h@s@n8-Dec-06 5:21 
QuestionRichEdit that like "VS.net Code Editor" Pin
god4k7-Dec-06 23:25
god4k7-Dec-06 23:25 
AnswerRe: RichEdit that like "VS.net Code Editor" Pin
Pete O'Hanlon7-Dec-06 23:42
mvePete O'Hanlon7-Dec-06 23:42 
GeneralRe: RichEdit that like "VS.net Code Editor" Pin
god4k9-Dec-06 1:39
god4k9-Dec-06 1:39 
QuestionRefreshing a page at frequent intervals Pin
meeram3957-Dec-06 23:23
meeram3957-Dec-06 23:23 
AnswerRe: Refreshing a page at frequent intervals Pin
Pete O'Hanlon7-Dec-06 23:45
mvePete O'Hanlon7-Dec-06 23:45 
GeneralRe: Refreshing a page at frequent intervals Pin
meeram3958-Dec-06 1:29
meeram3958-Dec-06 1:29 
GeneralRe: Refreshing a page at frequent intervals Pin
Pete O'Hanlon8-Dec-06 2:27
mvePete O'Hanlon8-Dec-06 2:27 
GeneralRe: Refreshing a page at frequent intervals Pin
meeram39511-Dec-06 23:54
meeram39511-Dec-06 23:54 
Questionethernet comm instead of serial Pin
faladrim7-Dec-06 23:09
faladrim7-Dec-06 23:09 
AnswerRe: ethernet comm instead of serial Pin
Ed.Poore7-Dec-06 23:13
Ed.Poore7-Dec-06 23:13 
GeneralRe: ethernet comm instead of serial Pin
faladrim7-Dec-06 23:21
faladrim7-Dec-06 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.