copying unsigned char array? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

copying unsigned char array?

Post by jazz » Sat Mar 17, 2007 9:00 am

Hey all. I'm trying to play around with wxImage alpha channel data and I seem to be a little stumped with how to handle unsigned char* 's properly.

Basically, wxImage::GetAlpha() returns a pointer to an unsigned char* array so I can directly manipulate the alpha channel. Before doing this though, I'd like to copy the array so I have an unmodified version that I can put back when I'm done.

So my question is, how can I copy an unsigned char* array? memcpy()? (which doesn't work). I'd also like to know how to get the length because strnlen() doesn't work either.

Anyone?
[INSERT LAME SIG HERE]

Martin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Thu Aug 11, 2005 11:04 am
Location: Karlsruhe, Germany

Post by Martin » Sat Mar 17, 2007 9:38 am

Just guessing here, but the length could be

wxImage::GetHeight() * wxImage::GetWidth()

I would try something like this:

Code: Select all

  unsigned char* alphaCopy = new unsigned char[length];
  memcpy(alphaCopy, wxImage::GetAlpha(), length);
How does your memcpy code look like?

jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Post by jazz » Sat Mar 17, 2007 10:38 am

Martin wrote:Just guessing here, but the length could be

wxImage::GetHeight() * wxImage::GetWidth()

I would try something like this:

Code: Select all

  unsigned char* alphaCopy = new unsigned char[length];
  memcpy(alphaCopy, wxImage::GetAlpha(), length);
How does your memcpy code look like?
Geez i can be such a n00b sometimes. I swear i tried that, except you just showed me that my syntax was incorrect. I was doing

Code: Select all

new unsigned char( length )
instead of

Code: Select all

new unsigned char[length]
which seems to cause a segfault.

Thanks heaps.
[INSERT LAME SIG HERE]

Post Reply