12 #error TnbCeBitmapImage.h is only supported on Windows CE platforms.
70 ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
72 IImagingFactory* pFactory = NULL;
73 IImage* pImage = NULL;
74 IBitmapImage* pBitmap = NULL;
76 HRESULT hr = ::CoCreateInstance(CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER
77 , IID_IImagingFactory,
reinterpret_cast<LPVOID*
>(&pFactory));
80 hr = pFactory->CreateImageFromFile(
CUnicode(lpszFileName), &pImage);
84 pImage->GetImageInfo(&info);
85 hr = pFactory->CreateBitmapFromImage(pImage, info.Width, info.Height
86 , PixelFormat24bppRGB, InterpolationHintDefault, &pBitmap);
93 if ( pFactory != NULL )
101 hr = pBitmap->LockBits(NULL, ImageLockModeRead, PixelFormat32bppARGB, &lockdata);
105 SIZE sz = { info.Width, info.Height };
107 const RGBQUAD* pSrc =
static_cast<const RGBQUAD*
>(lockdata.Scan0);
108 loop ( y, info.Height )
110 RGBQUAD* pDst = raw[y];
111 loop ( x, info.Width )
116 pBitmap->UnlockBits(&lockdata);
121 if ( pBitmap != NULL )
141 ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
149 ::DeleteFile(lpszFileName);
150 IImagingFactory* pFactory = NULL;
151 IImageEncoder* pEncoder = NULL;
152 IImageSink* pImageSink = NULL;
153 HRESULT hr = ::CoCreateInstance(CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER
154 , IID_IImagingFactory,
reinterpret_cast<LPVOID*
>(&pFactory));
157 ImageCodecInfo* pCodecInfo = NULL;
159 hr = pFactory->GetInstalledEncoders(&count, &pCodecInfo);
162 LPCWSTR lpFmtDes = NULL;
166 default: lpFmtDes = L
"BMP";
break;
167 case GIF: lpFmtDes = L
"GIF";
break;
168 case TIFF: lpFmtDes = L
"TIFF";
break;
169 case PNG: lpFmtDes = L
"PNG";
break;
170 case JPEG: lpFmtDes = L
"JPEG";
break;
172 CLSID encoderClassId;
177 encoderClassId = pCodecInfo[i].Clsid;
182 hr = pFactory->CreateImageEncoderToFile(&encoderClassId,
CUnicode(lpszFileName), &pEncoder);
186 if ( SUCCEEDED(hr) && fmt ==
JPEG )
188 EncoderParameters ep;
190 ep.Parameter[0].Guid = EncoderQuality ;
191 ep.Parameter[0].Type = 4;
192 ep.Parameter[0].NumberOfValues = 1;
193 ep.Parameter[0].Value = &quality;
194 hr = pEncoder->SetEncoderParameters(&ep);
198 hr = pEncoder->GetEncodeSink(&pImageSink);
203 imageInfo.Width = bm.
GetSize().cx;
204 imageInfo.Height = bm.
GetSize().cy;
205 imageInfo.RawDataFormat = ImageFormatMemoryBMP;
206 imageInfo.Flags |= SinkFlagsTopDown | SinkFlagsFullWidth;
209 imageInfo.PixelFormat = PixelFormat32bppARGB;
210 imageInfo.Flags |= SinkFlagsHasAlpha;
211 hr = pImageSink->BeginSink(&imageInfo, NULL);
215 ColorPalette pal = { 0 };
216 hr = pImageSink->SetPalette(&pal);
221 bmpData.Height = bm.
GetSize().cy;
222 bmpData.Width = bm.
GetSize().cx;
238 bmpData.Scan0 =raw.
Refer();
239 bmpData.PixelFormat = PixelFormat32bppARGB;
240 UINT bitsPerLine = bm.
GetSize().cx * 4 * 8;
241 UINT bitAlignment =
sizeof(LONG) * 8;
242 UINT bitStride = bitAlignment * (bitsPerLine / bitAlignment);
243 if ( (bitsPerLine % bitAlignment) != 0 )
245 bitStride += bitAlignment;
247 bmpData.Stride = bitStride / 8;
248 RECT rect = { 0, 0, bmpData.Width, bmpData.Height };
249 hr = pImageSink->PushPixelData(&rect, &bmpData, TRUE);
250 pImageSink->EndSink(S_OK);
251 pImageSink->Release();
253 if ( pEncoder != NULL )
255 pEncoder->TerminateEncoder();
259 if ( pFactory != NULL )
#define loop(VAR, CNT)
loop構文.
void SetClone(HBITMAP hBmp)
[設定] HBITMAPセット.
HBITMAP Detach(void)
[取得] デタッチ.
RGBQUAD * Refer(void)
[取得] データ参照.
CBitmapHandle Detach(void)
[設定] デタッチ.
bool IsEmpty(void) const
[確認] Empty状態確認.
const SIZE & GetSize(void) const
[取得] イメージサイズ取得.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
CBitmapHandle GetBitmapHandle(void)
[取得] ビットマップハンドル取得
CRawData _deprecated CreateRawData(void) const
[作成] 生データ作成.
static bool SaveBitmap(LPCTSTR lpszFileName, HBITMAP hBmp, EBitmapFormat fmt=BMP, long quality=80)
[作成] 画像ファイル作成.
static HBITMAP LoadBitmap(LPCTSTR lpszFileName)
[作成] 画像ファイル読込み.
const TYP * Ref(void) const
[取得] ポインタ取得
int Compare(LPCSTR P1, LPCSTR P2, INT_PTR len=-1, DWORD dwCmpFlags=0)
[比較] 文字列比較(ASCII/SJIS用)
TNB::CStrT< WCHAR > CUnicode
UNICODE文字列クラス
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー