PC Review


Reply
Thread Tools Rate Thread

Can I use an array of Color Values to make a Bitmap ?

 
 
Dave Harvey
Guest
Posts: n/a
 
      18th Aug 2003
I have an array of Color values, and from them I need to create Bitmap - so
far I have found 2 methods, both with drawbacks:

1) Create a bitmap of the right size, then "poke" the values into it
one-at-a-time using SetPixel - horribly slow and inefficient

2) Go out to unmanaged code and use the Scan0 field of the BitmapData
structure. I wish to avoid this, as I would like to have "clean" managed
code which won't get refused by "managed code only" machines.

So, why can't I find a simple method to pass an array of Color values to a
Bitmap constructor (or equivalent)? - this SHOULD be a fast, safe, managed
operation.

Am I missing something obvious, or is the .NET framework the one missing
something (like an important method or two?)

Dave Harvey
Medical Connections



 
Reply With Quote
 
 
 
 
MD Cobb
Guest
Posts: n/a
 
      18th Aug 2003

Try using the Scan0 of the managed BitmapData that will be
returned upon using the LockBits() method of Bitmap object.

Hope this helps.

MC
>-----Original Message-----
>I have an array of Color values, and from them I need to

create Bitmap - so
>far I have found 2 methods, both with drawbacks:
>
>1) Create a bitmap of the right size, then "poke" the

values into it
>one-at-a-time using SetPixel - horribly slow and

inefficient
>
>2) Go out to unmanaged code and use the Scan0 field of

the BitmapData
>structure. I wish to avoid this, as I would like to

have "clean" managed
>code which won't get refused by "managed code only"

machines.
>
>So, why can't I find a simple method to pass an array of

Color values to a
>Bitmap constructor (or equivalent)? - this SHOULD be a

fast, safe, managed
>operation.
>
>Am I missing something obvious, or is the .NET framework

the one missing
>something (like an important method or two?)
>
>Dave Harvey
>Medical Connections
>
>
>
>.
>

 
Reply With Quote
 
Dave Harvey
Guest
Posts: n/a
 
      18th Aug 2003
MC,

It WOULD help, if I could find a way of copying data into the "scan0"
address in a managed way. I know I can do this easily in unmanaged code,
but I was looking for a way of doing so without labelling my code as
"unsafe"

Dave

"MD Cobb" <(E-Mail Removed)> wrote in message
news:012601c365b7$3d9b14e0$(E-Mail Removed)...
>
> Try using the Scan0 of the managed BitmapData that will be
> returned upon using the LockBits() method of Bitmap object.
>
> Hope this helps.
>
> MC
> >-----Original Message-----
> >I have an array of Color values, and from them I need to

> create Bitmap - so
> >far I have found 2 methods, both with drawbacks:
> >
> >1) Create a bitmap of the right size, then "poke" the

> values into it
> >one-at-a-time using SetPixel - horribly slow and

> inefficient
> >
> >2) Go out to unmanaged code and use the Scan0 field of

> the BitmapData
> >structure. I wish to avoid this, as I would like to

> have "clean" managed
> >code which won't get refused by "managed code only"

> machines.
> >
> >So, why can't I find a simple method to pass an array of

> Color values to a
> >Bitmap constructor (or equivalent)? - this SHOULD be a

> fast, safe, managed
> >operation.
> >
> >Am I missing something obvious, or is the .NET framework

> the one missing
> >something (like an important method or two?)
> >
> >Dave Harvey
> >Medical Connections
> >
> >
> >
> >.
> >



 
Reply With Quote
 
MD Cobb
Guest
Posts: n/a
 
      18th Aug 2003
I might have missed it but I'm not sure what language
you're using. Here's a great article using VB.NET

http://support.microsoft.com/default.aspx?scid=kb;en-
us;Q319591

The System.Runtime.InteropServices.Marshal class is your
best friend in these circumstances. Methods like the Copy
one will help you. It's not entirely Managed because the
underlying bitmap structure is not managed either.

HTH
MC
>-----Original Message-----
>MC,
>
>It WOULD help, if I could find a way of copying data into

the "scan0"
>address in a managed way. I know I can do this easily in

unmanaged code,
>but I was looking for a way of doing so without labelling

my code as
>"unsafe"
>
>Dave
>
>"MD Cobb" <(E-Mail Removed)> wrote in message
>news:012601c365b7$3d9b14e0$(E-Mail Removed)...
>>
>> Try using the Scan0 of the managed BitmapData that will

be
>> returned upon using the LockBits() method of Bitmap

object.
>>
>> Hope this helps.
>>
>> MC
>> >-----Original Message-----
>> >I have an array of Color values, and from them I need

to
>> create Bitmap - so
>> >far I have found 2 methods, both with drawbacks:
>> >
>> >1) Create a bitmap of the right size, then "poke" the

>> values into it
>> >one-at-a-time using SetPixel - horribly slow and

>> inefficient
>> >
>> >2) Go out to unmanaged code and use the Scan0 field of

>> the BitmapData
>> >structure. I wish to avoid this, as I would like to

>> have "clean" managed
>> >code which won't get refused by "managed code only"

>> machines.
>> >
>> >So, why can't I find a simple method to pass an array

of
>> Color values to a
>> >Bitmap constructor (or equivalent)? - this SHOULD be a

>> fast, safe, managed
>> >operation.
>> >
>> >Am I missing something obvious, or is the .NET

framework
>> the one missing
>> >something (like an important method or two?)
>> >
>> >Dave Harvey
>> >Medical Connections
>> >
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you make Range Equal All Values in an Array? RyanH Microsoft Excel Programming 8 14th Nov 2008 08:47 PM
Make all variable values in a Array equal to 0 RyanH Microsoft Excel Programming 8 1st Aug 2008 02:34 AM
Populating array with color values Roger Microsoft ASP .NET 2 26th Jan 2004 02:13 AM
VB .NET Bitmap to byte array saima ashraf Microsoft Dot NET Compact Framework 1 31st Dec 2003 12:43 AM
Create a Bitmap from an Array Lance Microsoft VB .NET 6 22nd Dec 2003 03:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:17 AM.