调用Bitmap.Save始终调用到基类Image.Save

a609468036 2017-11-14 03:56:42
调用Bitmap.Save始终调用到基类Image.Save
...全文
146 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
a609468036 2017-11-17
  • 打赏
  • 举报
回复
@schlafenhamster 回复四楼,谢谢,后来是这样解决的,但我就是好奇 Bitmap有重载Save方法怎么用不了,编译的时候一直是Image.Save()
a609468036 2017-11-17
  • 打赏
  • 举报
回复
@zgl7903 回复三楼,我在msdn上看Bitmap有自己的save啊 Save(String) 将该 Image 保存到指定的文件或流。 (继承自 Image。)
schlafenhamster 2017-11-17
  • 打赏
  • 举报
回复
没看到 ?

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);
};
zgl7903 2017-11-15
  • 打赏
  • 举报
回复
Bitmap inherits from the Image class. 自身并没有Save的方法
schlafenhamster 2017-11-15
  • 打赏
  • 举报
回复
要有 decoder

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!");
}
a609468036 2017-11-14
  • 打赏
  • 举报
回复
我想调用Bitmap.Save保存图片,编译的时候调用的Image.Save,参数一直不对,Bitmap有重载啊

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧