|
-
September 13th, 2007, 12:50 PM
#1
Good idea here? I think so...
When dealing with device contexts in the past, I noticed that when shrinking images with StretchDIBits or StretchBlt with a bitmap selected into a memory DC, the images would not be smooth or correct.
So I wrote my own bitmap class. Here is the definition of it from my header file. Of course it relies on other classes, but this is just the interface.
Code:
class LORE_CORE_CLASS Bitmap : public GdiObject,public IImage
{
public:
Bitmap() throw();
Bitmap(HBITMAP hBitmap,bool bSystem) throw();
Bitmap(HBITMAP hBitmap,unsigned long * pPixelData) throw();
virtual ~Bitmap() throw();
// IImage
virtual Size GetSize() const throw();
virtual bool Resize(long nWidth,long nHeight) throw();
virtual bool Resize(Size nSize) throw();
virtual ColorValue * GetPixels() throw();
virtual const ColorValue * GetPixels() const throw();
virtual bool Scale(long nNewWidth,long nNewHeight,IImage * pDestImage) const throw();
virtual bool Scale(Size nNewSize,IImage * pDestImage) const throw();
virtual IImage * Scale(long nNewWidth,long nNewHeight) const throw();
virtual IImage * Scale(Size nNewSize) const throw();
virtual IImage * Scale(double lfRatio) const throw();
virtual IImage * Scale(double lfWidthRatio,double lfHeightRatio) const throw();
virtual bool CopyBlt(long srcX,long srcY,long nWidth,long nHeight,IImage * pDestImage,long destX,long destY) const throw();
virtual bool CopyBlt(const Point & src,const Size & nSize,IImage * pDestImage,const Point & dest) const throw();
virtual bool CopyBlt(const Rect & src,IImage * pDestImage,const Point & dest) const throw();
virtual IImage * CopyBlt(long srcX,long srcY,long nWidth,long nHeight) const throw();
virtual IImage * CopyBlt(const Point & src,const Size & nSize) const throw();
virtual IImage * CopyBlt(const Rect & src) const throw();
virtual bool StretchRect(const Rect & src,IImage * pDestImage,const Rect & dest) const throw();
virtual IImage * StretchRect(const Rect & src,const Size & nNewSize) const throw();
// Member Functions
void BltToHDC(HDC hDC,long x,long y) throw();
// Static Member Functions
static Bitmap * __stdcall CreateDIB(long nWidth,long nHeight) throw();
static Bitmap * __stdcall FromHDC(HDC hDC,long x,long y,long nWidth,long nHeight) throw();
static Bitmap * __stdcall LoadFromFile(const AnsiString & strFileName) throw();
static Bitmap * __stdcall LoadFromFile(const UnicodeString & strFileName) throw();
protected:
// Member Variables
unsigned long * PixelData;
Size Dimensions;
// Member Functions
void CopyLine(const Point & src,long nwidth,IImage * pDest,const Point & dest) const throw();
void StretchLine(const Point & src,long nWidth,IImage * pDest,const Point & dest,long nDestWidth) const throw();
void ShrinkLine(const Point & src,long nWidth,IImage * pDest,const Point & dest,long nDestWidth) const throw();
inline static ColorValue GetPixel(const ColorValue * pPixels,const Size & nDim,const Point & src) throw()
{
ColorValue clrValue = 0;
const long nHeight = nDim.Height;
const long nWidth = nDim.Width;
if (src.PosY >= 0 && src.PosY < nHeight && src.PosX >= 0 && src.PosX < nWidth)
{
const long nPosition = ((nHeight - src.PosY - 1) * nWidth) + src.PosX;
clrValue = pPixels[nPosition];
}
return clrValue;
}
inline static void SetPixel(ColorValue * pPixels,const Size & nDim,const Point & dest,ColorValue value) throw()
{
const long nHeight = nDim.Height;
const long nWidth = nDim.Width;
if (dest.PosY >= 0 && dest.PosY < nHeight && dest.PosX >= 0 && dest.PosX < nWidth)
{
const long nPosition = ((nHeight - dest.PosY - 1) * nWidth) + dest.PosX;
pPixels[nPosition] = value;
}
}
};
Now, my question is, when I get to writing the device context classes (PaintDC, ClientDC, WindowDC, MemoryDC, PrintDC) obviously only the memory DC will be able to have a bitmap selected into it...
So I am thinking... When I implement StretchBlt for the DCs, I should just call Bitmap::FromHDC to get a bitmap object that I want to stretch, stretch that into another, then use member function BltToHDC.
That will make alot of temporary memory overhead.
However, this way assures that the output will not look distorted/torn like StretchBlt and StretchDIBits have done on several occasions to me.
What do you think?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|