Click here to Skip to main content
15,891,529 members
Home / Discussions / C#
   

C#

 
GeneralRe: Log Off Computer Fails Pin
Abdul Rahman Hamidy1-Sep-09 23:48
Abdul Rahman Hamidy1-Sep-09 23:48 
GeneralRe: Log Off Computer Fails Pin
monstale2-Sep-09 0:51
monstale2-Sep-09 0:51 
GeneralRe: Log Off Computer Fails Pin
Abdul Rahman Hamidy2-Sep-09 0:55
Abdul Rahman Hamidy2-Sep-09 0:55 
GeneralRe: Log Off Computer Fails Pin
Vishwamr150619-Sep-09 9:04
Vishwamr150619-Sep-09 9:04 
QuestionRGB-Byte[] to BGR-Bitmap? Pin
blacksheep131-Aug-09 2:09
blacksheep131-Aug-09 2:09 
AnswerRe: RGB-Byte[] to BGR-Bitmap? Pin
Henry Minute31-Aug-09 2:22
Henry Minute31-Aug-09 2:22 
GeneralRe: RGB-Byte[] to BGR-Bitmap? Pin
blacksheep131-Aug-09 2:51
blacksheep131-Aug-09 2:51 
GeneralRe: RGB-Byte[] to BGR-Bitmap? Pin
Henry Minute31-Aug-09 5:08
Henry Minute31-Aug-09 5:08 
I have put your test image generator code into a Windows Forms Application and I get a vertical RED stripe, then a vertical GREEN stripe then a vertical BLUE stripe. This is what I would expect.

Here is my code:
public partial class ByteArrayToImageForm : Form
{
    private int f_WIDTH = 100;
    private int f_HEIGHT = 100;
    private byte[] testImageArray;

    public ByteArrayToImageForm()
    {
        InitializeComponent();

        this.testImageArray = this.MakeImage();
    }

    public byte[] MakeImage()
    {
        int x = 0;
        byte[] Img = new Byte[f_WIDTH * f_HEIGHT * 3];
        for (int i = 0; i < f_WIDTH * f_HEIGHT * 3; i += 3, x++)
        {
            if (x == f_WIDTH)
            {
                x = 0;
            }
            if (x <= f_WIDTH / 3)
            {
                Img[i] = 255;
                Img[i + 1] = 0;
                Img[i + 2] = 0;
            }
            if (x > f_WIDTH / 3 && x < (f_WIDTH / 3) * 2)
            {
                Img[i] = 0;
                Img[i + 1] = 255;
                Img[i + 2] = 0;
            }
            if (x > (f_WIDTH / 3) * 2)
            {
                Img[i] = 0;
                Img[i + 1] = 0;
                Img[i + 2] = 255;
            }
        }
        return Img;
    }

    private void ByteArrayToImageForm_Paint(object sender, PaintEventArgs e)
    {
        int arrayIndex = 0;
        int x = 0;
        int y = 0;

        Bitmap visibleBitmap = new Bitmap(this.f_WIDTH, this.f_HEIGHT, PixelFormat.Format24bppRgb);
        while (arrayIndex < this.testImageArray.Length)
        {
            visibleBitmap.SetPixel(x, y,
                Color.FromArgb(this.testImageArray[arrayIndex],
                this.testImageArray[arrayIndex + 1],
                this.testImageArray[arrayIndex + 2]));
            x++;
            if (x >= this.f_WIDTH)
            {
                x = 0;
                y++;
            }
            arrayIndex += 3;
        }

        int drawX = (this.ClientRectangle.Width - visibleBitmap.Width) / 2;
        int drawY = (this.ClientRectangle.Height - visibleBitmap.Height) / 2;

        e.Graphics.DrawImage(visibleBitmap, drawX, drawY);
    }
}


Try it out. **NOTE** I have dispensed with the Convert.ToByte parts from your code as they are not necessary, although it does not alter the output (I tried both ways).

So unless you were using Convert.ToByte because you were converting from int, for example, which might explain your problems, I am at a loss.

Sorry! Smile | :)

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

QuestionVisual Studio 2005 - Create Cubes with Analysis Services Pin
Mschauder31-Aug-09 1:37
Mschauder31-Aug-09 1:37 
AnswerRe: Visual Studio 2005 - Create Cubes with Analysis Services Pin
monstale31-Aug-09 2:09
monstale31-Aug-09 2:09 
QuestionHow to create MimeFilter in c# Pin
svt gdwl31-Aug-09 1:21
svt gdwl31-Aug-09 1:21 
QuestionEncrypt and Decrypt an assembly Pin
Member 444864731-Aug-09 1:19
Member 444864731-Aug-09 1:19 
AnswerRe: Encrypt and Decrypt an assembly Pin
Henry Minute31-Aug-09 2:24
Henry Minute31-Aug-09 2:24 
GeneralRe: Encrypt and Decrypt an assembly Pin
Member 444864731-Aug-09 17:31
Member 444864731-Aug-09 17:31 
QuestionOCR Pin
abbd31-Aug-09 0:18
abbd31-Aug-09 0:18 
AnswerRe: OCR Pin
monstale31-Aug-09 0:35
monstale31-Aug-09 0:35 
AnswerRe: OCR Pin
Rajesh R Subramanian31-Aug-09 0:50
professionalRajesh R Subramanian31-Aug-09 0:50 
QuestionRemoting server in Window Service Pin
puneet_shadija31-Aug-09 0:08
puneet_shadija31-Aug-09 0:08 
AnswerRe: Remoting server in Window Service Pin
stancrm31-Aug-09 0:40
stancrm31-Aug-09 0:40 
GeneralRe: Remoting server in Window Service Pin
puneet_shadija31-Aug-09 19:37
puneet_shadija31-Aug-09 19:37 
Questionsplit in C# Pin
rummer30-Aug-09 23:41
rummer30-Aug-09 23:41 
AnswerRe: split in C# Pin
stancrm30-Aug-09 23:47
stancrm30-Aug-09 23:47 
AnswerRe: split in C# Pin
Member 321664631-Aug-09 0:02
Member 321664631-Aug-09 0:02 
GeneralRe: split in C# Pin
OriginalGriff31-Aug-09 0:14
mveOriginalGriff31-Aug-09 0:14 
GeneralRe: split in C# Pin
Luc Pattyn31-Aug-09 0:43
sitebuilderLuc Pattyn31-Aug-09 0:43 

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.