도전2022

24 bit bmp to rGB565 file conversion[c#] 본문

소스코드

24 bit bmp to rGB565 file conversion[c#]

hotdigi 2012. 5. 8. 10:35

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/1cab307d-2f5a-489f-8653-f5a9e86a6146



using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
  
class Program
  {
    
static void Main(string[] args)
    {
      
Bitmap bmp = new Bitmap("C:\\Temp\\Sample Pictures\\Tree.jpg");
      
byte[] b = new byte[bmp.Width * bmp.Height * 2];
      
GCHandle gch = GCHandle.Alloc(b, GCHandleType.Pinned);
      
IntPtr scan0 = gch.AddrOfPinnedObject();
      
Bitmap dest = new Bitmap(bmp.Width, bmp.Height,4 * ((bmp.Width * 16 + 31) / 32), PixelFormat.Format16bppRgb565, scan0);
      
using (Graphics g = Graphics.FromImage(dest))
      {
        g.DrawImage(bmp, 0, 0);
      }
      gch.Free();
      dest.Save(
"C:\\Temp\\WFConv.bmp"ImageFormat.Bmp);
    }
  }
}

'소스코드' 카테고리의 다른 글

[qt]관련 자료 검색  (0) 2012.05.23
블루투스 관련 자료  (0) 2012.05.21
PC에서 안드로이드 실행  (0) 2012.05.04
c#, wpf 에서 파일 주소를 브러쉬 데이터로 만들자.  (0) 2012.05.03
SHGetFolderPath  (0) 2012.04.25