C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-03-2009, 08:46 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 1
SetDIBitsToDevice - Displaying 24 bit image

Hi,

I am trying to display a SGI format image (.rgb) into a picturebox using SetDIBitsToDevice API.

The image file does not have header information.

But calling this function raises a argument exception, that parameter is incorrect. But I am not able to identify the incorrect parameter.
Code:
//API declaration
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public static extern int SetDIBitsToDevice(IntPtr hDC, int DestX, int DestY, uint wDestWidth, uint wDestHeight, int SrcX, int SrcY, uint uStartScan, uint uScanLines, byte[] lpBits, ref BITMAPINFO BitsInfo, uint uColorUse);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

//Structures
public struct PALETTEENTRY
        {
            public byte peRed;
            public byte peGreen;
            public byte peBlue;
            //public byte peFlags;
        }

        public struct BITMAPINFOHEADER
        {
            public uint biSize;
            public int biWidth;
            public int biHeight;
            public ushort biPlanes;
            public ushort biBitCount;
            public uint biCompression;
            public uint biSizeImage;
            public int biXPelsPerMeter;
            public int biYPelsPerMeter;
            public uint biClrUsed;
            public uint biClrImportant;
        }
        public struct BITMAPINFO
        {
            public BITMAPINFO(BITMAPINFOHEADER bmiHeader)
            {
                this.bmiHeader = bmiHeader;
                bmiColors = new PALETTEENTRY[256];
            }
            public BITMAPINFOHEADER bmiHeader;
            public PALETTEENTRY[] bmiColors;
        }

        public const int BI_RGB = 0;
        public const int DIB_RGB_COLORS = 0;
Calling this API
Code:
byte[] data = System.IO.File.ReadAllBytes("test.rgb");

//arranging bits to display RGB file correctly
byte[] data3 = (new ReadImage(ref data)).ReadChannels();

                PrintImage.BITMAPINFOHEADER bmiHeader = new PrintImage.BITMAPINFOHEADER();
                bmiHeader.biSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(bmiHeader);
                bmiHeader.biWidth = 400;
                bmiHeader.biHeight = -400;
                //bmiHeader.biPlanes = 1;
                bmiHeader.biBitCount = 24;
                //bmiHeader.biClrUsed = 0;
                //bmiHeader.biClrImportant = 0;
                bmiHeader.biCompression = PrintImage.BI_RGB;
                bmiHeader.biSizeImage = 400 * 400;

                PrintImage.BITMAPINFO bmi = new PrintImage.BITMAPINFO(bmiHeader);

                IntPtr lhDC = PrintImage.CreateCompatibleDC(PrintImage.GetWindowDC(pictureBox1.Handle));

                int test = PrintImage.SetDIBitsToDevice(lhDC, 0, 0, 400, 400, 0, 0, 0, 400, data3, ref bmi, PrintImage.DIB_RGB_COLORS);
I know I have hardcoded few things like width, height etc., but for this example, it has been fixed.

Where could be the problem? I tried same API in VC++ (VS 2008), and it si displaying the image correctly.

What other options are available? I am ready/willing to learn this stuff.

Thank you
Harsh Gupta is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HotSpot image controls (web) novacain C# Programming 0 06-25-2008 04:27 AM
Button Displaying Image mrafcho001 Windows Programming 4 12-03-2005 02:14 PM
Displaying a PNG image grep Windows Programming 5 07-07-2005 08:27 PM
Problem displaying bitmaps batman123 Game Programming 2 01-09-2005 02:01 AM
Image displaying homeyg C++ Programming 16 01-03-2005 06:27 PM


All times are GMT -6. The time now is 02:34 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22