GDI+图像文件分解与合并

27 篇文章 0 订阅
//合并
void CBmp2MDlg::ImagePack(LPCTSTR sPath,LPCTSTR sType)
{
int i,n = m_list.GetItemCount();
if( n<=1 ) return;


CLSID clsid;
GetEncoderClsid( sType,&clsid );


//
int w,h;
CString ss,sFile;
sFile.Format( _T("%s_Packs.%s"),sPath,GetType(sType) );
int iW,iH; //总宽度、总高度
iW = iH = 0;
CArray<Bitmap*,Bitmap*> arr;


//以第一个为准
ss = m_list.GetItemText(0,0);
Bitmap bt( ss );
w = bt.GetWidth();
h = bt.GetHeight();
iW = w;
iH = h;
Bitmap *bts = bt.Clone(0,0,bt.GetWidth(),bt.GetHeight(),0);
arr.Add( bts );
for( i=1;i<n;i++ )
{
ss = m_list.GetItemText(i,0);
Bitmap bt( ss );
iW += bt.GetWidth(); //总宽度,只考虑横向
Bitmap *bts = bt.Clone(0,0,bt.GetWidth(),bt.GetHeight(),0);
arr.Add( bts );
}


//新建指定大小的图片
Bitmap bmp( iW,iH );
//从它得到绘制设备
Graphics *gc = Graphics::FromImage( &bmp );
iW = 0;
for( i=0;i<arr.GetCount();i++ )
{
Bitmap *bt = arr[i];
//从指定长度开始叠加图片
gc->DrawImage( bt,iW,0 );
iW += bt->GetWidth();
}
bmp.Save( sFile,&clsid,NULL );


//
for( i=0;i<arr.GetCount();i++ )
{
delete arr[i];
arr[i] = NULL;
}
arr.RemoveAll();
arr.FreeExtra();


ShellExecute( NULL,_T("open"),sPath,NULL,NULL,SW_SHOW );


}

//--------------------------------------------------
//分解,目前仅考虑 BMP 格式
void CBmp2MDlg::ImageUnPack(LPCTSTR sPath,LPCTSTR sType,int x,int y)
{
if( NULL==m_bitmap ) return; //must!
//
Bitmap *bmp = m_bitmap;
int w = bmp->GetWidth();
int h = bmp->GetHeight();
CLSID clsid;
GetEncoderClsid( sType,&clsid );


CString ss;
int i,k=1;
for( i=0;i<w;i+=x,k++ ) //只考虑横向
{
//新建指定大小的图片
Bitmap bt(x,y);
//从它得到绘制设备
Graphics *gc = Graphics::FromImage( &bt );
//从原图片上截取指定大小的图片贴到这个新建的图片的上面
gc->DrawImage( bmp,RectF(0,0,x,y),i,0,x,y,UnitPixel ); 
//
ss.Format( _T("%s%s_%d.%s"),sPath,m_sFileTitle,k,GetType(sType) );
//保存到指定路径
bt.Save( ss,&clsid,NULL );
//
delete gc;
gc = NULL;
}


ShellExecute( NULL,_T("open"),sPath,NULL,NULL,SW_SHOW );
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值