Graphics and Multimedia Topics include: GDI+, drawing 2D/3D, printing and Managed DirectX and the XNA Framework

Go Back  Xtreme .NET Talk > .NET > Graphics and Multimedia > Using SetPixel with PixelFormat::Format8bppIndexed


Reply
 
Thread Tools Display Modes
  #1  
Old 08-14-2003, 09:27 PM
meretrix meretrix is offline
Newcomer

Preferred language:
C++
 
Join Date: Aug 2003
Posts: 13
meretrix is on a distinguished road
Default Using SetPixel with PixelFormat::Format8bppIndexed



After figuring out how to manipulate the palette on a Bitmap object, I now can't manage to make SetPixel work without throwing an exception. I've tried:

SetPixel(x, y, FromArgb(0xAARRGGBB))
SetPixel(x, y, PredefinedColour)
SetPixel(x, y, Palette->Entries[0])
SetPixel(x, y, 0)

Help please...
Reply With Quote
  #2  
Old 08-14-2003, 09:28 PM
Volte Volte is offline
Neutiquam Erro

Preferred language:
C# and VB.NET
 
Join Date: Nov 2002
Posts: 2,172
Volte is on a distinguished road
Default

What exception?
Reply With Quote
  #3  
Old 08-14-2003, 09:33 PM
meretrix meretrix is offline
Newcomer

Preferred language:
C++
 
Join Date: Aug 2003
Posts: 13
meretrix is on a distinguished road
Default

System.ArgumentException. This is what happens when I try to use a predefined color or FromArgb. When I try to do it with a simple integer it just won't compile.
Reply With Quote
  #4  
Old 08-14-2003, 09:45 PM
Volte Volte is offline
Neutiquam Erro

Preferred language:
C# and VB.NET
 
Join Date: Nov 2002
Posts: 2,172
Volte is on a distinguished road
Default

Are you making sure that x and y are Integers and not Doubles or Longs or anything? If Option Strict is on, it won't allow narrowing conversions.
Reply With Quote
  #5  
Old 08-14-2003, 10:27 PM
meretrix meretrix is offline
Newcomer

Preferred language:
C++
 
Join Date: Aug 2003
Posts: 13
meretrix is on a distinguished road
Default

They're definitely ints (set up as such in the for loops before). It seems like the function's not set up to handle a colour index, 'cos no matter what I do it either crashes or won't compile...
Reply With Quote
  #6  
Old 08-20-2003, 11:27 AM
mickn66 mickn66 is offline
Regular
 
Join Date: Nov 2002
Posts: 53
mickn66 is on a distinguished road
Default

I think the problem is the pixel format (Format8bppIndexed). Some things VB can't do with an image in an indexed format. Can you convert the image to a non-indexed format? That was ultimately the solution to a similar problem I was having.
Reply With Quote
  #7  
Old 08-20-2003, 12:13 PM
OnErr0r OnErr0r is offline
Newcomer
 
Join Date: Jul 2003
Location: Debug Window
Posts: 19
OnErr0r is on a distinguished road
Default

You could LockBits on the bitmap, then either use unsafe and access the pixels directly (fast). Or, use Marshal.Copy to copy from the Scan0 IntPtr to an array, alter various pixels in said array and Marshal.Copy it back (relatively slow). Then UnlockBits.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net: get|setpixel speedproblem IWeb Graphics and Multimedia 2 09-13-2003 02:20 AM
SetPixel in VB.Net Epo Graphics and Multimedia 9 08-04-2003 10:37 PM

Advertisement:







Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe