Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
GeneralRe: Console.writeline not working from a windows app. Pin
Heath Stewart30-Jul-04 7:32
protectorHeath Stewart30-Jul-04 7:32 
GeneralRe: Console.writeline not working from a windows app. Pin
Admiral Ackbar30-Jul-04 8:19
Admiral Ackbar30-Jul-04 8:19 
GeneralDrag n drop treeview Nodes between two different applications Pin
misterbear30-Jul-04 2:02
misterbear30-Jul-04 2:02 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
Heath Stewart30-Jul-04 5:58
protectorHeath Stewart30-Jul-04 5:58 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
misterbear31-Jul-04 4:59
misterbear31-Jul-04 4:59 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
Heath Stewart31-Jul-04 5:26
protectorHeath Stewart31-Jul-04 5:26 
GeneralMessage Removed Pin
30-Jul-04 1:01
wibblewibblewibble30-Jul-04 1:01 
GeneralRe: Image Class Problem Pin
Bret Mulvey9-Aug-04 17:54
Bret Mulvey9-Aug-04 17:54 
You should be able to do it by looking at the raw data bytes. This is more complicated than GetPixel(), but the System.Color structure definitely only supports 8bpp. The upside is that this method can be a lot faster than calling GetPixel thousands of times.

To get at the raw data for a System.Drawing.Bitmap you first have to lock the bits (so the array doesn't move around in memory while you're doing unsafe pointer stuff), then you can get a pointer to the start of a particular scan line, which will be a pointer to the raw array of bytes for that scanline. All of this requires the "unsafe" keyword, which requires a special compiler flag.

Inside the unsafe { ... } block, first call LockBits() on the Bitmap to get a BitmapData structure. Then you can use the Scan0 property of the BitmapData to get a pointer to the first scanline. In your case you would cast this to a (ushort*) type, since each 16bit value is a ushort. Incrementing the pointer will point to subsequent ushort's on the same scanline.

To get to the next row (scan line) of the image, add the value of the Stride property of the BitmapData to the Scan0 value to get the pointer to the start of the second scan line.

I don't have a 48bpp image to try this on, but here's some code for a 32bpp image which you can use as a starting point:
using (Bitmap bmp = new Bitmap("image.tif"))
{
   int[,] raw = new int[bmp.Width, bmp.Height];
   Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
   unsafe
   {
      BitmapData data = bmp.LockBits(rect, 
         ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
      int max = int.MinValue;
      byte *p = (byte *) data.Scan0;
      for (int y = 0; y < bmp.Height; y++)
      {
         byte *q = p;
         for (int x = 0; x < bmp.Width; x++)
         {
            byte red = *(q++);
            byte grn = *(q++);
            byte blu = *(q++);
            raw[x, y] = blu + 256 * grn + 65536 * red;
         }
         p += data.Stride;
      }
      bmp.UnlockBits(data);
   }
}
In your case you'll want ushort instead of byte everywhere, and you wouldn't be saving the pixels as 32-bit ints of course, but the logic is the same. It's also possible that I have the red/blu values backwards here, but you can figure that out.
GeneralWebBrowser's Document Complete event Pin
profoundwhispers29-Jul-04 23:02
profoundwhispers29-Jul-04 23:02 
GeneralRe: WebBrowser's Document Complete event Pin
HiltonG30-Jul-04 2:30
HiltonG30-Jul-04 2:30 
GeneralRe: WebBrowser's Document Complete event Pin
profoundwhispers30-Jul-04 8:33
profoundwhispers30-Jul-04 8:33 
GeneralRe: WebBrowser's Document Complete event Pin
Dave Kreskowiak30-Jul-04 4:27
mveDave Kreskowiak30-Jul-04 4:27 
GeneralInvoking a Win32 DLL from C# Pin
rana7429-Jul-04 23:00
rana7429-Jul-04 23:00 
GeneralRe: Invoking a Win32 DLL from C# Pin
Heath Stewart30-Jul-04 5:53
protectorHeath Stewart30-Jul-04 5:53 
GeneralRe: Invoking a Win32 DLL from C# Pin
rana741-Aug-04 16:18
rana741-Aug-04 16:18 
GeneralRe: Invoking a Win32 DLL from C# Pin
Heath Stewart4-Aug-04 5:04
protectorHeath Stewart4-Aug-04 5:04 
Questionhow do i pass null to dateTime variable Pin
robmays29-Jul-04 22:56
robmays29-Jul-04 22:56 
AnswerRe: how do i pass null to dateTime variable Pin
Ryan Roberts30-Jul-04 0:15
Ryan Roberts30-Jul-04 0:15 
GeneralRe: how do i pass null to dateTime variable Pin
robmays30-Jul-04 0:17
robmays30-Jul-04 0:17 
QuestionHow to passing parameters from eVC++ to a running C# program? Pin
ting66829-Jul-04 22:40
ting66829-Jul-04 22:40 
AnswerRe: How to passing parameters from eVC++ to a running C# program? Pin
Heath Stewart30-Jul-04 5:40
protectorHeath Stewart30-Jul-04 5:40 
Questionmatching regex at exact index? Pin
Roger Alsing29-Jul-04 21:44
Roger Alsing29-Jul-04 21:44 
AnswerRe: matching regex at exact index? Pin
Heath Stewart30-Jul-04 4:55
protectorHeath Stewart30-Jul-04 4:55 
GeneralRe: matching regex at exact index? Pin
Roger Alsing30-Jul-04 5:14
Roger Alsing30-Jul-04 5:14 
GeneralRe: matching regex at exact index? Pin
Roger Alsing1-Aug-04 7:25
Roger Alsing1-Aug-04 7:25 

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.