Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to convert the picture on the panel to bytes.

I did that but it works only for the backgroungimage of a panel.

in my program I use 3ds max to draw on the panel

I need to convert the picture on the panel to bytes

this is the function I use to get the bytes of the backgroungimage of the panel

 

private void fun()

{

pna1.BackgroundImage.Save("m"); //m is the name of the file

bm = new Bitmap("m");

 

//the size of the panel is 240*160

byte [,] matrix= new byte [240,160];

 

byte red=0, green=0, blue=0;

byte [] test=new byte [1];

for (int y=0; y < 160; y++)

{

for (int x =0; x < 240; x++)

{

Color u=bm.GetPixel (x ,y);

//I need only one byte represent each pixel

blue = (byte)(u.B/64*64);

green = (byte)(u.G/32*8);

red =(byte)(u.R/32);

matrix[x,y]=(byte)(red + green + blue);

}

}

}

  • Leaders
Posted (edited)

First of all, if you draw to a control using some GDI or GDI+ function, you cannot examine the pixels. You can only get the pixel information if you draw to a bitmap object.

 

How to draw to a bitmap:

Bitmap bmp, Graphics gfx;

bmp = new Bitmap(40, 40);  //40 by 40 bitmap.
gfx = Graphics.FromImage(bmp); //This is the key line.

gfx.DrawLine(Pens.Red, 0, 0, 32, 32);

Edited by Iceplug

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...