把两张图片从外部载入到软件中,然后把两张图片拼接成一张图片保存到本地。请问下,这该用vc.net 怎么做啊?
------解决方案--------------------------------------------------------
CxImage 看一下
void MergedImage(CString filename1,CString filename2,CString m_strEndFileName)//合并图片
{
int w1,h1,w2,h2,bpp;//w1,h1为原始尺寸大小 w2,h2为合并图后的大小
w1 = img1.GetWidth();
h1 = img1.GetHeight();
w2 = w1 ;
h2 = h1 + h1/2;
//分别缩略第一张、第二张图
CxImage img1SL,img2SL;
float scale = 0.5;
img1SL = img1;//
img1SL.Resample(img1.GetWidth()*scale,img1.GetHeight()*scale);
img1SL.Save(filename1,CXIMAGE_FORMAT_JPG);
img2SL = img2;
img2SL.Resample(img2.GetWidth()*scale,img2.GetHeight()*scale);
img2SL.Save(filename2,CXIMAGE_FORMAT_JPG);
//
bpp = img1.GetBpp();
img3.Create(w2,h2,bpp);
img3.MixFrom(img1,0,h1/2);
img3.MixFrom(img1SL,0,0);
img3.MixFrom(img2SL,w1/2,0);
CString m_strSavePic;
m_strSavePic.Format("%s%s",filename2,".jpg");
img3.Save(m_strEndFileName,CXIMAGE_FORMAT_JPG);//最终的图片目录
::DeleteFile(filename1);
::DeleteFile(filename2);
}
------解决方案--------------------------------------------------------
用GDI+的方式解决这个问题,参考以下代码
rcImg(0,0,nImageWidth,nImageHeight);
BitmapData bmData;
m_pBitmap->LockBits(&rcImg,ImageLockModeRead
------解决方案--------------------------------------------------------
ImageLockModeWrite,
PixelFormat32bppARGB, &bmData);
ASSERT(bmData.PixelFormat == PixelFormat32bppARGB);
//滤镜效果
int nWidth = bmData.Width; nHeight = bmData.Height;
DWORD * pdwStart = (DWORD *)bmData.Scan0; //第一行扫描线的位置
UINT nSize = nWidth * nHeight;
for(UINT i = 0; i < nSize; i++)
{
DWORD dwR = (pdwStart[i] >> 16) & 0xFF;
DWORD dwG = (pdwStart[i] >> 8) & 0xFF;
DWORD dwB = pdwStart[i] & 0xFF;
DWORD dwV = (dwR * 30 + dwG * 59 + dwB * 11) / 100;
pdwStart[i]= (pdwStart[i] & 0xFF000000)
------解决方案--------------------------------------------------------
(dwV<<16)
------解决方案--------------------------------------------------------
(dwV<<8)
------解决方案--------------------------------------------------------
dwV;
}
m_pBitmap->UnlockBits(&bmData);
原理是直接打开图片的二进制数据,并逐行进行处理。
最后用 save 方法保存即可
建议以 PixelFormat32bppARGB 格式打开,这样好处理,每个像素对应于一个 DWORD 值