读出二个BMP,到HDC,然后合并成为一个HDC,把HDC中的图片,生成BMP怎么弄呢?
读出二个BMP,到HDC,然后合并成为一个HDC,把HDC中的图片,生成BMP怎么弄呢? --------------------编程问答-------------------- CBitmap bitmap1,bitmap2;CDC memDC,FinalDC;
HBITMAP hBitmap;
BITMAP Bmp1,Bmp2;
int x,y;
FinalDC.CreateCompatibleDC(NULL);
//初始化Bmp2
bitmap2.CreateBitmapIndirect(&Bmp2);
FinalDC.SelectObject(&bitmap2);
memDC.CreateCompatibleDC(NULL);
//处理第一副图
hBitmap = (HBITMAP)::LoadImage(NULL,"First.bmp",IMAGE_BITMAP,0,0,
LR_DEFAULTSIZE | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
bitmap1.Attach(hBitmap);
bitmap1.GetBitmap(&Bmp1);
memDC.SelectObject(&bitmap1);
FinalDC.BitBlt(0,0,Bmp1.bmWidth,Bmp1.bmHeight ,&memDC,0,0,SRCCOPY);
x=Bmp1.bmWidth;
y=Bmp1.bmHeight
//处理第二副图
hBitmap = (HBITMAP)::LoadImage(NULL,"Second.bmp",IMAGE_BITMAP,0,0,
LR_DEFAULTSIZE | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
bitmap1.Attach(hBitmap);
memDC.SelectObject(&bitmap1);
FinalDC.BitBlt(x,y,Bmp1.bmWidth,Bmp1.bmHeight ,&memDC,0,0,SRCCOPY); --------------------编程问答-------------------- 能看懂不? 要不翻译成vb的? --------------------编程问答-------------------- 要哦 --------------------编程问答-------------------- hMemDc = CreateCompatibleDC(Picture2.hdc)
'将Picture1的BitMap图指定给hMemDc
Call SelectObject(hMemDc, Picture1.Handle)
Call BitBlt(Picture2.hdc, 0, i, width5, 1, _
hMemDc, 0, i, SRCCOPY)
貌似这样使最小化的方式说明了 调用api CreateCompatibleDC SelectObject BitBlt
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" _
(ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Const SRCCOPY = &HCC0020
bitblt 的最后一个参数有很多种,需要自己注意一下
--------------------编程问答-------------------- 能看懂不??api的作用你 google 一下我不贴了.... --------------------编程问答-------------------- 要是你的HDC是PictureBox,那试一下直接SavePicture看看.....貌似可以直接保存为BMP来着... --------------------编程问答-------------------- 问题的关键点在BitBlt的最后一个参数,比较高深 --------------------编程问答-------------------- 怎么个合并法?上、下、左、右、叠加? --------------------编程问答--------------------
也是....我只想着叠加了,其他的都没考虑 --------------------编程问答-------------------- 应该是叠加 --------------------编程问答--------------------
没错,SavePicture方法也只能保存为BMP格式的位图。
还有,楼主的图片大小未知怎么个拼接法?? --------------------编程问答-------------------- 如何将合并图片放到picturebox中呢?
Option Explicit
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateBitmapIndirect Lib "gdi32" (lpBitmap As BITMAP) As Long
Private Type BITMAP '14 bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" _
(ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, _
ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Dim hMemDC1 As Long
Dim hMemDC2 As Long
Dim h As Long
Dim c As Long
Dim g As Long
Dim i As Long
Dim aa As BITMAP
Dim bb As BITMAP
Dim pic As Picture
Private Sub Command1_Click()
' Me.Picture = LoadPicture("")
hMemDC1 = CreateCompatibleDC(hdc)
Set pic = LoadPicture(App.Path & "\" & "1.bmp")
h = pic.Handle
c = SelectObject(hMemDC1, h)
i = GetObject(h, Len(aa), aa)
g = BitBlt(Me.hdc, 0, 0, aa.bmWidth, aa.bmHeight, hMemDC1, 0, 0, SRCCOPY)
Form1.Print c, g, i
hMemDC2 = CreateCompatibleDC(hdc)
Set pic = LoadPicture(App.Path & "\" & "2.bmp")
h = pic.Handle
c = SelectObject(hMemDC2, h)
i = GetObject(h, Len(aa), aa)
g = BitBlt(Me.hdc, 150, 0, aa.bmWidth, aa.bmHeight, hMemDC2, 0, 0, SRCCOPY)
Form1.Print c, g, i
End Sub --------------------编程问答-------------------- 的 --------------------编程问答-------------------- 貌似你用picture的hdc就比较好了,为什么要用me.hdc呢? --------------------编程问答-------------------- 如果我想用me.hdc呢,该怎么进行存储图片呢 --------------------编程问答-------------------- http://topic.csdn.net/t/20030317/00/1538596.html
补充:VB , API