.NETGURU
Images generation
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-drawing' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Shan Nunez, Eduardo

    Hi there.
    
        Following the late questions about creating images on the
fly, I've come up with this thing.

        I wanted to create bitmaps from scratch and manipulate them
without loading them from file;
    Chris trick of creating a graphics directly from a bitmap,

        dim b as New system.drawing.bitmap(w, h,
pixelformat.Format16bppRgb555)
        dim g as graphics = graphics.fromimage(b)
    doesn't work in C#. Instead, I use the following workaround,

            System.Drawing.Bitmap bitmap= new
System.Drawing.Bitmap(32, 16);
            System.IntPtr hBitmap = bitmap.GetHbitmap();
            System.Drawing.Image img =
System.Drawing.Image.FromHbitmap(hBitmap);
            System.Drawing.Graphics graphics =
Graphics.FromImage(img);

        Does anybody know if there is a better way to do it?

    
Thanks in advance,
    
Ed.

Reply to this message...
 
    
Jeffrey Widmer
Ed,
You might want to join aspngcs (c-sharp list)
http://www.asplists.com/asplists/aspngcs.asp
and post the vb.net code and ask for the c# translation. There's a lot of
people on that list who are excellent at translating from vb.net to c#.
-Jeff

-----Original Message-----
From: Shan Nunez, Eduardo [mailto:Click here to reveal e-mail address]
Sent: Thursday, January 24, 2002 6:47 AM
To: ngfx-drawing
Subject: [ngfx-drawing] Images generation

    Hi there.

        Following the late questions about creating images on the
fly, I've come up with this thing.

        I wanted to create bitmaps from scratch and manipulate them
without loading them from file;
    Chris trick of creating a graphics directly from a bitmap,

        dim b as New system.drawing.bitmap(w, h,
pixelformat.Format16bppRgb555)
        dim g as graphics = graphics.fromimage(b)
    doesn't work in C#. Instead, I use the following workaround,

            System.Drawing.Bitmap bitmap= new
System.Drawing.Bitmap(32, 16);
            System.IntPtr hBitmap = bitmap.GetHbitmap();
            System.Drawing.Image img =
System.Drawing.Image.FromHbitmap(hBitmap);
            System.Drawing.Graphics graphics =
Graphics.FromImage(img);

        Does anybody know if there is a better way to do it?

Thanks in advance,

Ed.

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp = JOIN/QUIT

Reply to this message...
 
    
Ryan Trudelle-Schwarz (VIP)
Yes, this is very possible:

Bitmap myBitmap = new Bitmap(32,16);
Graphics myGraphics = Graphics.FromImage(myBitmap);

Works fine in c#

You can also define the format if you wish when creating the Bitmap.

Hth, Ryan

-----Original Message-----
From: Shan Nunez, Eduardo [mailto:Click here to reveal e-mail address]

    Hi there.
    
        Following the late questions about creating images on
the
fly, I've come up with this thing.

        I wanted to create bitmaps from scratch and manipulate
them
without loading them from file;
    Chris trick of creating a graphics directly from a bitmap,

        dim b as New system.drawing.bitmap(w, h,
pixelformat.Format16bppRgb555)
        dim g as graphics = graphics.fromimage(b)
    doesn't work in C#. Instead, I use the following workaround,

            System.Drawing.Bitmap bitmap= new
System.Drawing.Bitmap(32, 16);
            System.IntPtr hBitmap = bitmap.GetHbitmap();
            System.Drawing.Image img =
System.Drawing.Image.FromHbitmap(hBitmap);
            System.Drawing.Graphics graphics =
Graphics.FromImage(img);

        Does anybody know if there is a better way to do it?

    
Thanks in advance,
    
Ed.

Reply to this message...
 
    
Shan Nunez, Eduardo

OK, that's just what I tried at first,
but as it didn't (and still doesn't) work in my VS .NET
(I get an 'Out of memory' exception in run time),
I had put the hbitmap in between. Maybe it has something
to do with the beta 2 I'm using.

                Thanks,

                        Ed.

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: jueves, 24 de enero de 2002 20:49
To: ngfx-drawing
Subject: [ngfx-drawing] RE: Images generation

Yes, this is very possible:

Bitmap myBitmap = new Bitmap(32,16);
Graphics myGraphics = Graphics.FromImage(myBitmap);

Works fine in c#

You can also define the format if you wish when creating the Bitmap.

Hth, Ryan

-----Original Message-----
From: Shan Nunez, Eduardo [mailto:Click here to reveal e-mail address]

    Hi there.
    
        Following the late questions about creating images on
the
fly, I've come up with this thing.

        I wanted to create bitmaps from scratch and manipulate
them
without loading them from file;
    Chris trick of creating a graphics directly from a bitmap,

        dim b as New system.drawing.bitmap(w, h,
pixelformat.Format16bppRgb555)
        dim g as graphics = graphics.fromimage(b)
    doesn't work in C#. Instead, I use the following workaround,

            System.Drawing.Bitmap bitmap= new
System.Drawing.Bitmap(32, 16);
            System.IntPtr hBitmap = bitmap.GetHbitmap();
            System.Drawing.Image img =
System.Drawing.Image.FromHbitmap(hBitmap);
            System.Drawing.Graphics graphics =
Graphics.FromImage(img);

        Does anybody know if there is a better way to do it?

    
Thanks in advance,
    
Ed.

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-drawing.asp = JOIN/QUIT

Reply to this message...
 
    
Ryan Trudelle-Schwarz (VIP)
Send the code you are using, I'll test it here. The below was almost
directly copied from something I'm currently using (b2) and is working
fine.

-----Original Message-----
From: Shan Nunez, Eduardo [mailto:Click here to reveal e-mail address]

OK, that's just what I tried at first,
but as it didn't (and still doesn't) work in my VS .NET
(I get an 'Out of memory' exception in run time),
I had put the hbitmap in between. Maybe it has something
to do with the beta 2 I'm using.

                Thanks,

                        Ed.

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]

Yes, this is very possible:

Bitmap myBitmap = new Bitmap(32,16);
Graphics myGraphics = Graphics.FromImage(myBitmap);

Works fine in c#

You can also define the format if you wish when creating the Bitmap.

Hth, Ryan

Reply to this message...
 
 
System.Drawing.Bitmap
System.Drawing.Graphics
System.Drawing.Image
System.IntPtr




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification