Click here to Skip to main content
15,921,989 members
Home / Discussions / C#
   

C#

 
GeneralDataTable's ever changing row index Pin
fuzzlog26-May-05 8:15
fuzzlog26-May-05 8:15 
GeneralRe: DataTable's ever changing row index Pin
pubududilena26-May-05 19:55
pubududilena26-May-05 19:55 
GeneralRe: DataTable's ever changing row index Pin
Anonymous26-May-05 20:05
Anonymous26-May-05 20:05 
GeneralRe: DataTable's ever changing row index Pin
pubududilena26-May-05 20:40
pubududilena26-May-05 20:40 
GeneralUsing custom controls. Pin
Nick Z.26-May-05 7:29
Nick Z.26-May-05 7:29 
GeneralRe: Using custom controls. Pin
Christian Graus26-May-05 14:25
protectorChristian Graus26-May-05 14:25 
GeneralRe: Using custom controls. Pin
Nick Z.26-May-05 14:40
Nick Z.26-May-05 14:40 
Questionhow to send a packet to device , the simplest way? Pin
jinzhecheng26-May-05 7:12
jinzhecheng26-May-05 7:12 
AnswerRe: how to send a packet to device , the simplest way? Pin
Phillip H. Blanton26-May-05 13:04
Phillip H. Blanton26-May-05 13:04 
QuestionCareer in 2005 + n? Pin
WDI26-May-05 6:30
WDI26-May-05 6:30 
AnswerRe: Career in 2005 + n? Pin
Judah Gabriel Himango26-May-05 7:13
sponsorJudah Gabriel Himango26-May-05 7:13 
AnswerRe: Career in 2005 + n? Pin
Anonymous27-May-05 16:31
Anonymous27-May-05 16:31 
QuestionHow to retrieve Image from access Database Pin
eng.mohamed26-May-05 5:55
eng.mohamed26-May-05 5:55 
AnswerRe: How to retrieve Image from access Database Pin
Judah Gabriel Himango26-May-05 9:13
sponsorJudah Gabriel Himango26-May-05 9:13 
GeneralOdbcDataReader!! Pin
trk_wakil26-May-05 5:04
trk_wakil26-May-05 5:04 
GeneralRe: OdbcDataReader!! Pin
pubududilena26-May-05 19:34
pubududilena26-May-05 19:34 
Generalsocket handling Pin
cyrus10926-May-05 4:49
cyrus10926-May-05 4:49 
GeneralRe: socket handling Pin
S. Senthil Kumar26-May-05 5:06
S. Senthil Kumar26-May-05 5:06 
GeneralRe: socket handling Pin
cyrus10926-May-05 5:12
cyrus10926-May-05 5:12 
GeneralRe: socket handling Pin
S. Senthil Kumar26-May-05 6:19
S. Senthil Kumar26-May-05 6:19 
GeneralRe: socket handling Pin
cyrus10926-May-05 10:17
cyrus10926-May-05 10:17 
GeneralHandling Win32 logical palette's in C# Pin
Rahsas26-May-05 3:41
Rahsas26-May-05 3:41 
I'm having a hard time handling logical palette's in C#. What I'm trying to do, is extract a palette from a 256 color bitmap, place it into a logical palette, select the logical palette as the current system palette, realize the new palette, and then draw the 256 color bitmap to the screen using the colors in it's palette (which is now the current system palette). Everything seems to be working great up to the point where I start drawing the bitmap. When I'm running the desktop in 256 color mode, it will only draw the bitmap in 16 colors (Windows standard colors) even though the palette is selected and realized correctly. I've included the code I've used to implement this. If anyone knows how to get this to work correctly, let me know. Thanks in advance! Anyway, here is the code I'm using.

<br />
IntPtr hWindowDC = IntPtr.Zero;<br />
<br />
public class User<br />
{<br />
     [DllImport("user32.dll")]<br />
     public static extern IntPtr GetDC(IntPtr hWnd);<br />
<br />
     [DllImport("user32.dll")]<br />
     public static extern void ReleaseDC(IntPtr hWnd, IntPtr hDC);<br />
}<br />
<br />
public class Gdi<br />
{<br />
     [DllImport("gdi32.dll")]<br />
     public static extern IntPtr SelectPalette(IntPtr hDC, IntPtr hPalette, bool bForceBackground);<br />
<br />
     [DllImport("gdi32.dll")]<br />
     public static extern int RealizePalette(IntPtr hDC);<br />
<br />
     [DllImport("gdi32.dll")]<br />
     public static extern int GetDeviceCaps(IntPtr hDC, int nIndex);<br />
<br />
     [DllImport("gdi32.dll")]<br />
     public static extern IntPtr CreatePalette([In] IntPtr lpLogPalette);<br />
<br />
     public const int PC_RESERVED = 0x01;     // palette index used for animation<br />
     public const int PC_EXPLICIT = 0x02;     // palette index is explicit to device<br />
     public const int PC_NOCOLLAPSE = 0x04;     // do not match color to system palette<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct LOGPALETTE<br />
{<br />
     public ushort palVersion;<br />
     public ushort palNumEntries;<br />
     public PALETTEENTRY palPalEntry;<br />
<br />
     public LOGPALETTE(ushort entries)<br />
     {<br />
          this.palVersion = 0x300;<br />
          this.palNumEntries = entries;<br />
          this.palPalEntry = new PALETTEENTRY(0,0,0,0);<br />
     }<br />
          <br />
     public int Length<br />
     {<br />
          get<br />
          {<br />
               return Marshal.SizeOf(palVersion) + Marshal.SizeOf(palNumEntries) + (this.palNumEntries * 4);<br />
          }<br />
     }<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct PALETTEENTRY<br />
{<br />
     public byte peRed;<br />
     public byte peGreen;<br />
     public byte peBlue;<br />
     public byte peFlags;<br />
<br />
     public PALETTEENTRY(byte red, byte green, byte blue, byte flags)<br />
     {<br />
          this.peRed = red;<br />
          this.peGreen = green;<br />
          this.peBlue = blue;<br />
          this.peFlags = flags;<br />
     }<br />
<br />
     public override string ToString()<br />
     {<br />
          return string.Format("{0} {1} {2}", Convert.ToString(peRed, 10), Convert.ToString(peGreen, 10), Convert.ToString(peBlue, 10));<br />
     }<br />
<br />
}<br />
<br />
<br />
private static void LoadImagePalette()<br />
{<br />
     Assembly exeAssembly = Assembly.GetExecutingAssembly();<br />
<br />
     Stream imgStream = null;<br />
<br />
     imgStream = exeAssembly.GetManifestResourceStream("MyPalette.image256.bmp");<br />
     if( !(null==imgStream) )<br />
     {<br />
          Image image = Bitmap.FromStream( imgStream );// as Bitmap;<br />
          LOGPALETTE logPal = new LOGPALETTE((ushort)(image.Palette.Entries.Length));<br />
<br />
          byte []paletteBytes = new byte[image.Palette.Entries.Length*4];<br />
<br />
          for (int i=0; i < image.Palette.Entries.Length; i++)<br />
          {<br />
               paletteBytes[(i*4)] = image.Palette.Entries[i].R; // red<br />
               paletteBytes[(i*4)+1] = image.Palette.Entries[i].G; // green<br />
               paletteBytes[(i*4)+2] = image.Palette.Entries[i].B; // blue<br />
               paletteBytes[(i*4)+3] = 0; // flags<br />
          }<br />
<br />
          IntPtr ptrPal = Marshal.AllocHGlobal(logPal.Length);<br />
          Marshal.StructureToPtr(logPal, ptrPal, true);<br />
<br />
          IntPtr palPalEntryAddress = new IntPtr(ptrPal.ToInt32() + Marshal.SizeOf(logPal.palVersion) + Marshal.SizeOf(logPal.palNumEntries) );<br />
          Marshal.Copy(paletteBytes, 0, palPalEntryAddress, paletteBytes.Length);<br />
                    <br />
          IntPtr hPalette = Gdi.CreatePalette(ptrPal);<br />
<br />
          Gdi.SelectPalette(hWindowDC, hPalette, false);//false);<br />
          Gdi.RealizePalette(hWindowDC);<br />
<br />
          Graphics newGraphics = Graphics.FromHdc(hWindowDC);<br />
          newGraphics.DrawImage(image, 0, 0);<br />
<br />
          if (ptrPal != IntPtr.Zero)<br />
               Marshal.FreeHGlobal(ptrPal);<br />
                    <br />
          imgStream.Close();<br />
<br />
     }<br />
}<br />

GeneralWord automation selecting tray Pin
Master_Blaster26-May-05 3:05
Master_Blaster26-May-05 3:05 
GeneralRemoting Q. Pin
Member 199247026-May-05 1:06
Member 199247026-May-05 1:06 
GeneralRe: Remoting Q. Pin
S. Senthil Kumar26-May-05 2:59
S. Senthil Kumar26-May-05 2:59 

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.