16,472
社区成员
发帖
与我相关
我的任务
分享
class Bitmap : public Image
{
public:
friend class Image;
friend class CachedBitmap;
Bitmap(
IN const WCHAR *filename,
IN BOOL useEmbeddedColorManagement = FALSE
);
Bitmap(
IN IStream *stream,
IN BOOL useEmbeddedColorManagement = FALSE
);
static Bitmap* FromFile(
IN const WCHAR *filename,
IN BOOL useEmbeddedColorManagement = FALSE
);
static Bitmap* FromStream(
IN IStream *stream,
IN BOOL useEmbeddedColorManagement = FALSE
);
Bitmap(IN INT width,
IN INT height,
IN INT stride, PixelFormat format,
IN BYTE* scan0);
Bitmap(IN INT width,
IN INT height,
IN PixelFormat format = PixelFormat32bppARGB);
Bitmap(IN INT width,
IN INT height,
IN Graphics* target);
Bitmap* Clone(IN const Rect& rect,
IN PixelFormat format);
Bitmap* Clone(IN INT x,
IN INT y,
IN INT width,
IN INT height,
IN PixelFormat format);
Bitmap* Clone(IN const RectF& rect,
IN PixelFormat format);
Bitmap* Clone(IN REAL x,
IN REAL y,
IN REAL width,
IN REAL height,
IN PixelFormat format);
Status LockBits(IN const Rect* rect,
IN UINT flags,
IN PixelFormat format,
OUT BitmapData* lockedBitmapData);
Status UnlockBits(IN BitmapData* lockedBitmapData);
Status GetPixel(IN INT x,
IN INT y,
OUT Color *color);
Status SetPixel(IN INT x,
IN INT y,
IN const Color &color);
Status SetResolution(IN REAL xdpi,
IN REAL ydpi);
// GDI interop:
Bitmap(IN IDirectDrawSurface7* surface);
Bitmap(IN const BITMAPINFO* gdiBitmapInfo,
IN VOID* gdiBitmapData);
Bitmap(IN HBITMAP hbm,
IN HPALETTE hpal);
Bitmap(IN HICON hicon);
Bitmap(IN HINSTANCE hInstance,
IN const WCHAR * bitmapName);
static Bitmap* FromDirectDrawSurface7(IN IDirectDrawSurface7* surface);
static Bitmap* FromBITMAPINFO(IN const BITMAPINFO* gdiBitmapInfo,
IN VOID* gdiBitmapData);
static Bitmap* FromHBITMAP(IN HBITMAP hbm,
IN HPALETTE hpal);
static Bitmap* FromHICON(IN HICON hicon);
static Bitmap* FromResource(IN HINSTANCE hInstance,
IN const WCHAR * bitmapName);
Status GetHBITMAP(IN const Color& colorBackground,
OUT HBITMAP *hbmReturn);
Status GetHICON(HICON *hicon);
#ifdef DCR_USE_NEW_250932
private:
Bitmap(const Bitmap &);
Bitmap& operator=(const Bitmap &);
#endif
protected:
Bitmap(GpBitmap *nativeBitmap);
};
void AlphaBmp()
{
Bitmap OldBmp(L"red24.bmp");
int w = OldBmp.GetWidth();
if(w==0) return;
int h=OldBmp.GetHeight();
if(h==0) return;
//
Bitmap newBmp(w,h,PixelFormat32bppPARGB);
for(int i=0; i<h; i++)
{
BYTE a;//=128;//cr.GetA();
Color cr;
for(int j=0; j<w; j++)
{
OldBmp.GetPixel(j,i,&cr);
COLORREF cref=cr.ToCOLORREF();
if( cref == RGB(255,255,255)) a=0; // 0 表示完全透明
else a=128;// 255表示不透明
newBmp.SetPixel(j,i,Color(a,cr.GetR(),cr.GetG(),cr.GetB()));
}
}
//
CLSID Clsid;
GetEncoderClsid(L"image/png", &Clsid);
WCHAR fileName[60]= L"HalfRed.png";
//
newBmp.Save(fileName,&Clsid);
AfxMessageBox("HalfRed.png Saved!");
}