예제 #1
0
        static Bitmap ColorToBitmap(int w, int h, Color[] argb)
        {
            //WL("argb.Length = "+argb.Length+" buff = "+buffer.Length);
            Bitmap     bmp  = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            LockBitmap lbmp = new LockBitmap(bmp);

            lbmp.LockBits();
            for (int hi = 0; hi < h; hi++)
            {
                for (int wi = 0; wi < w; wi++)
                {
                    Color c = argb[hi * w + wi];
                    lbmp.SetPixel(wi, hi, c);
                }
            }
            lbmp.UnlockBits();
            return(bmp);
        }
예제 #2
0
        static byte[] RawGreyToImage(int w, int h, byte[] buffer)
        {
            Bitmap     bmp  = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            LockBitmap lbmp = new LockBitmap(bmp);

            lbmp.LockBits();
            for (int b = 0; b < buffer.Length; b += 2)
            {
                int  pi = b * 2;              //for every 2 gray bytes we write 4 argb bytes
                byte c  = (byte)BitConverter.ToInt16(buffer, b);
                lbmp.Pixels[pi]     = c;
                lbmp.Pixels[pi + 1] = c;
                lbmp.Pixels[pi + 2] = c;
                lbmp.Pixels[pi + 3] = 255;               //a
            }
            lbmp.UnlockBits();

            MemoryStream s = new MemoryStream();

            bmp.Save(s, ImageFormat.Jpeg);
            return(s.ToArray());
        }
예제 #3
0
        static byte[] RawGreyToImage(int w,int h,byte[] buffer)
        {
            Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
            LockBitmap lbmp = new LockBitmap(bmp);
            lbmp.LockBits();
            for(int b=0; b<buffer.Length;b+=2) {
                int pi = b*2; //for every 2 gray bytes we write 4 argb bytes
                byte c = (byte)BitConverter.ToInt16(buffer,b);
                lbmp.Pixels[pi] = c;
                lbmp.Pixels[pi+1] = c;
                lbmp.Pixels[pi+2] = c;
                lbmp.Pixels[pi+3] = 255; //a
            }
            lbmp.UnlockBits();

            MemoryStream s = new MemoryStream();
            bmp.Save(s,ImageFormat.Jpeg);
            return s.ToArray();
        }
예제 #4
0
 static Bitmap ColorToBitmap(int w,int h, Color[] argb)
 {
     //WL("argb.Length = "+argb.Length+" buff = "+buffer.Length);
     Bitmap bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
     LockBitmap lbmp = new LockBitmap(bmp);
     lbmp.LockBits();
     for (int hi = 0; hi < h; hi++)
     {
         for (int wi = 0; wi < w; wi++)
         {
             Color c = argb[hi * w + wi];
             lbmp.SetPixel(wi, hi, c);
         }
     }
     lbmp.UnlockBits();
     return bmp;
 }