Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Сохранить *.ICO Добавлено: 20.07.05 04:47  

Автор вопроса:  Softer | Web-сайт: hware.org.ua | ICQ: 203660381  
Есть такая прога:
в picImg хранится картинка для перевода

Option Explicit
Private Declare Function CreateIconIndirect Lib "user32.dll" (piconinfo As ICONINFO) As Long
Private Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" (ByRef lpPictDesc As PictDesc, riid As Guid, ByVal fOwn As Long, lplpvObj As Any)
Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32.dll" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function SetTextColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetTextColor Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function SetBkColor Lib "gdi32.dll" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetBkColor Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (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 RasterOpConstants) As Long
Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Type ICONINFO
    fIcon           As Long
    xHotspot        As Long
    yHotspot        As Long
    hBmMask         As Long
    hBmColor        As Long
End Type
Private Type PictDesc
    cbSizeofStruct  As Long
    picType         As Long
    hImage          As Long
    xExt            As Long
    yExt            As Long
End Type
Private Type Guid
    Data1           As Long
    Data2           As Integer
    Data3           As Integer
    Data4(0 To 7)   As Byte
End Type
Dim hIcon As Long
Private Sub Form_Load()
    hIcon = PicToIco(picImg.hdc, 32, 32)
    Me.Picture = IconToPicture(hIcon)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Call DestroyIcon(hIcon)
End Sub
Public Function PicToIco(ByVal hSrcDC As Long, _
                         ByVal nWidth As Long, _
                         ByVal nHeight As Long, _
                Optional ByVal lMaskColor As Long = &HFFFF) As Long
    Dim hDCMask As Long, hDCColor As Long, hScrDC As Long, hDstDC As Long
    Dim hBmMask As Long, hBmColor As Long
    Dim hBmColorOld As Long, hBmMaskOld As Long
    Dim Ico As ICONINFO
    hScrDC = GetDC(0&)
    hDstDC = CreateCompatibleDC(hSrcDC)
    hBmColor = CreateCompatibleBitmap(hSrcDC, nWidth, nHeight)
    hBmMask = CreateBitmap(nWidth, nHeight, 1&, 1&, ByVal 0&)
    hDCColor = CreateCompatibleDC(hSrcDC)
    hBmColorOld = SelectObject(hDCColor, hBmColor)
    Call SetBkColor(hDCColor, GetBkColor(hSrcDC))
    Call SetTextColor(hDCColor, GetTextColor(hSrcDC))
    Call BitBlt(hDCColor, 0&, 0&, nWidth, nHeight, hSrcDC, 0&, 0&, vbSrcCopy)
    hDCMask = CreateCompatibleDC(hSrcDC)
    hBmMaskOld = SelectObject(hDCMask, hBmMask)
    If lMaskColor = &HFFFF Then lMaskColor = GetPixel(hSrcDC, 0&, 0&)
    Call SetBkColor(hDCColor, lMaskColor)
    Call SetTextColor(hDCColor, vbWhite)
    Call BitBlt(hDCMask, 0, 0, nWidth, nHeight, hDCColor, 0, 0, vbSrcCopy)
    Call SetTextColor(hDCColor, vbBlack)
    Call SetBkColor(hDCColor, vbWhite)
    Call BitBlt(hDCColor, 0, 0, nWidth, nHeight, hDCMask, 0, 0, &H220326)
    Call BitBlt(hDstDC, 0, 0, nWidth, nHeight, hDCMask, 0, 0, vbSrcAnd)
    Call BitBlt(hDstDC, 0, 0, nWidth, nHeight, hDCColor, 0, 0, vbSrcPaint)
    Ico.fIcon = True
    Ico.hBmColor = SelectObject(hDCColor, hBmColorOld)
    Ico.hBmMask = SelectObject(hDCMask, hBmMaskOld)
    PicToIco = CreateIconIndirect(Ico)
    Call DeleteObject(Ico.hBmColor)
    Call DeleteDC(hDCColor)
    Call DeleteObject(Ico.hBmMask)
    Call DeleteDC(hDCMask)
    Call DeleteDC(hDstDC)
    Call ReleaseDC(0&, hScrDC)
End Function
Private Function IconToPicture(ByVal hIcon As Long) As IPicture
    Dim iPic As IPicture, picDes As PictDesc, iidIPicture As Guid
    With picDes
        .cbSizeofStruct = Len(picDes)
        .picType = &H3
        .hImage = hIcon
    End With
    With iidIPicture
        .Data1 = &H7BF80980
        .Data2 = &HBF32
        .Data3 = &H101A
        .Data4(0) = &H8B
        .Data4(1) = &HBB
        .Data4(2) = &H0
        .Data4(3) = &HAA
        .Data4(4) = &H0
        .Data4(5) = &H30
        .Data4(6) = &HC
        .Data4(7) = &HAB
    End With
    Call OleCreatePictureIndirect(picDes, iidIPicture, True, IconToPicture)
End Function


А теперь вопрос:
как ЭТО заставить сохранять полученную иконку в файл *.ICO?

Ответить

  Ответы Всего ответов: 12  

Номер ответа: 1
Автор ответа:
 Barsik



Разработчик Offline Client

ICQ: 343368641 

Вопросов: 17
Ответов: 686
 Web-сайт: barsik.newmail.ru
 Профиль | | #1
Добавлено: 20.07.05 17:28
юзай готовые примеры в примерах...

Ответить

Номер ответа: 2
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #2
Добавлено: 20.07.05 18:07
я пример отсылал, bmp2ico... тут...

Ответить

Номер ответа: 3
Автор ответа:
 Softer



ICQ: 203660381  

Вопросов: 29
Ответов: 205
 Web-сайт: hware.org.ua
 Профиль | | #3
Добавлено: 21.07.05 04:11
sne, проблема в том, что мне необходимо СОХРАНИТЬ полученное изображение формата ICO в файл.

Ответить

Номер ответа: 4
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #4
Добавлено: 21.07.05 12:42
Сорри, неверно название примера написал... оно CrIco называлось...

Поискал на винте примеры, нашел bmp2ico - он сохраняет на диск иконку

Ответить

Номер ответа: 5
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #5
Добавлено: 21.07.05 12:42
Сорри, неверно название примера написал... оно CrIco называлось...

Поискал на винте примеры, нашел bmp2ico - он сохраняет на диск иконку

Ответить

Номер ответа: 6
Автор ответа:
 someone



Вопросов: 215
Ответов: 1596
 Web-сайт: 123
 Профиль | | #6
Добавлено: 21.07.05 14:23
а в примерах есть такое?

Ответить

Номер ответа: 7
Автор ответа:
 someone



Вопросов: 215
Ответов: 1596
 Web-сайт: 123
 Профиль | | #7
Добавлено: 21.07.05 14:25
а кстати, как из ико в бмп перегнать? есть такая проблема :(
ACDSee конечно руль, но хотелось бы знать еще и как это на vb будет выглядеть...

Ответить

Номер ответа: 8
Автор ответа:
 someone



Вопросов: 215
Ответов: 1596
 Web-сайт: 123
 Профиль | | #8
Добавлено: 21.07.05 14:27
ага, нашел!
кому надо - вот ссылка:
http://vbnet.ru/samples/download.aspx?id=438

Ответить

Номер ответа: 9
Автор ответа:
 Softer



ICQ: 203660381  

Вопросов: 29
Ответов: 205
 Web-сайт: hware.org.ua
 Профиль | | #9
Добавлено: 22.07.05 04:12
2Empro. ЗАгружаешь *.ico в PictureBox.
Затем SavePicture picIco.picture, "C:\icon.bmp"

2sne. Скинь на мыло please... SofterSoft@narod.ru.
Спасибо.

Ответить

Номер ответа: 10
Автор ответа:
 pvq



Вопросов: 8
Ответов: 17
 Профиль | | #10 Добавлено: 23.07.05 08:39
Вот тут **p://www.vb.kiev.ua/code/graph/ лежат примерно штук 5 всяких ICO едиторов,очень хороших

Ответить

Номер ответа: 11
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #11
Добавлено: 23.07.05 10:55
почтовый клиент не работает :) так что вот форма:

в Picture1 - картинкку помести
в Picture3 - иконку помести

VERSION 5.00
Begin VB.Form frmBmp2Icon
   BorderStyle     =   1  'Fixed Single
   Caption         =   "BMP to ICO, ICO to BMP"
   ClientHeight    =   4410
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4395
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   294
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   293
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox Picture2
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Height          =   540
      Left            =   690
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   14
      Top             =   2640
      Width           =   540
   End
   Begin VB.PictureBox Picture1
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Height          =   540
      Left            =   660
      Picture         =   "Bmp2Icon.frx":0000
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   13
      Top             =   1080
      Width           =   540
   End
   Begin VB.CommandButton Command4
      Height          =   345
      Left            =   3930
      TabIndex        =   11
      ToolTipText     =   "Clear display of new bmp"
      Top             =   3630
      Width           =   135
   End
   Begin VB.CommandButton Command3
      Height          =   345
      Left            =   1620
      TabIndex        =   10
      ToolTipText     =   "Clear display of new ico"
      Top             =   3630
      Width           =   135
   End
   Begin VB.PictureBox picImage
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      ForeColor       =   &H80000008&
      Height          =   540
      Left            =   3750
      ScaleHeight     =   34
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   34
      TabIndex        =   9
      Top             =   30
      Visible         =   0   'False
      Width           =   540
   End
   Begin VB.PictureBox picMask
      Appearance      =   0  'Flat
      AutoRedraw      =   -1  'True
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   540
      Left            =   3750
      ScaleHeight     =   34
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   34
      TabIndex        =   8
      Top             =   600
      Visible         =   0   'False
      Width           =   540
   End
   Begin VB.CommandButton Command2
      Caption         =   "Ico to Bmp"
      Height          =   345
      Left            =   2640
      TabIndex        =   7
      Top             =   3630
      Width           =   1185
   End
   Begin VB.CommandButton Command1
      Caption         =   "Bmp to Ico"
      Height          =   345
      Left            =   330
      TabIndex        =   6
      Top             =   3630
      Width           =   1185
   End
   Begin VB.PictureBox Picture4
      BackColor       =   &H80000005&
      Height          =   540
      Left            =   2850
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   1
      Top             =   2610
      Width           =   540
   End
   Begin VB.PictureBox Picture3
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Height          =   540
      Left            =   2850
      Picture         =   "Bmp2Icon.frx":0282
      ScaleHeight     =   32
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   32
      TabIndex        =   0
      Top             =   1080
      Width           =   540
   End
   Begin VB.Label Label5
      Caption         =   ";(Size of examples here is 32x32 pixels)"
      Height          =   195
      Left            =   90
      TabIndex        =   12
      Top             =   30
      Width           =   3285
   End
   Begin VB.Line Line1
      X1              =   142
      X2              =   142
      Y1              =   48
      Y2              =   264
   End
   Begin VB.Label Label4
      Caption         =   "New bmp (saved in file ""Fromico.bmp"";)"
      Height          =   405
      Left            =   2400
      TabIndex        =   5
      Top             =   2100
      Width           =   1575
   End
   Begin VB.Label Label3
      Caption         =   "Original ico"
      Height          =   285
      Left            =   2670
      TabIndex        =   4
      Top             =   690
      Width           =   855
   End
   Begin VB.Label Label2
      Caption         =   "New ico (saved in file  ""Frombmp.ico"";)"
      Height          =   465
      Left            =   300
      TabIndex        =   3
      Top             =   2070
      Width           =   1485
   End
   Begin VB.Label Label1
      Caption         =   "Original bmp"
      Height          =   285
      Left            =   480
      TabIndex        =   2
      Top             =   690
      Width           =   975
   End
End
Attribute VB_Name = "frmBmp2Icon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Bmp2Ico.frm
'
' By Herman Liu
'
' To show how to make an icon file out of a bitmap, and vice versa.
'
' Sometimes you see a nice bitmap picture, or part of it, and want to make it as an icon.
' You can do what you want now (Just add "file open" and "file save" functions to open the
' bmp/ico file and save the ico/bmp file respectively. That is, for example, instead of
' using the existing image in Picture1, load your own. When it is converted into an icon in
' Picture2, save it to a file name you want.  Of course, in this case, you may want to fix
' the size of the image first).
'
' Notes: If you have a copy of my "IconEdit", and you want to give yourself a challenge, you
' can incorporate this code into it. This will be fairly easy. (Basically, you only need to
' add a few menu items, as almost all the APIs here are already there, so are all major
' procedures).  In "IconEdit" I have left out many functions, since I don't want to blur the
' essentials.  For example, if I open up just the Region function, there would be
' implications on Flip/Rotate/Invert and I have to allow region dragging and so on.)
'
Option Explicit

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 CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
    ByVal nWidth As Long, ByVal nHeight 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

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Declare Function CreateIconIndirect Lib "user32" (icoinfo As ICONINFO) As Long

Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (lppictDesc As _
     pictDesc, riid As Guid, ByVal fown As Long, ipic As IPicture) As Long
     
Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, _
     icoinfo As ICONINFO) As Long
     
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, _
    ByVal crColor As Long) As Long
    
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight _
    As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    
'Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, _
      ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long

Private Type ICONINFO
    fIcon As Long
    xHotspot As Long
    yHotspot As Long
    hBMMask As Long
    hBMColor As Long
End Type

Private Type Guid
    ;Data1 As Long
    ;Data2 As Integer
    ;Data3 As Integer
    ;Data4(7) As Byte
End Type

Private Type pictDesc
    cbSizeofStruct As Long
    picType As Long
    hImage As Long
    xExt As Long
    yExt As Long
End Type

Const PICTYPE_BITMAP = 1
Const PICTYPE_ICON = 3
Dim iGuid As Guid
Dim hdcMono
Dim bmpMono
Dim bmpMonoTemp
Const stdW = 32
Const stdH = 32
Dim mresult



Private Sub Form_Load()
     ' Create monochrome hDC and bitmap
    hdcMono = CreateCompatibleDC(hdc)
    bmpMono = CreateCompatibleBitmap(hdcMono, stdW, stdH)
    bmpMonoTemp = SelectObject(hdcMono, bmpMono)
    With iGuid
         .Data1 = &H20400
         .Data4(0) = &HC0
         .Data4(7) = &H46
    End With
      ' Just to make sure
    picImage.AutoRedraw = True
    picMask.AutoRedraw = True
End Sub



Private Sub command1_click()
    On Error Resume Next
    picImage.Picture = LoadPicture()
    picMask.Picture = LoadPicture()
    Picture2.Picture = LoadPicture()
    
    '------------------------------------------------
    ' As the main aim of this program is for learning,
    ' variations are advanced for your own study.
    '------------------------------------------------
    '-------------------
    ' Alternative 1
    ' For general use
    '-------------------
    command1_Alternative
    Exit Sub
    
    
    '-------------------
    ' Alternative 2
    ' If you have a known use at a particular place
    '-------------------
        ' Let us select a background color here (just a matter of choice
        ' e.g. form1.backcolor, vbGray, so that the transparent part will
        ' blend in the surrounding backcolor when loaded)
'    picImage.BackColor = Picture1.BackColor
        ' Area having the following color is to be left out as it is meant
        ' to be transparent
'    ;Dim mtransp As Long
'    mtransp = Picture1.Point(0, 0)
        ' Create transparent part
'    CreateTransparent Picture1, picImage, mtransp
        ' Make sure no Autoredraw for picMask with this alternative
'    picMask.AutoRedraw = False
        ' Create a mask
'    CreateMask_viaMemoryDC picImage, picMask
'    mresult = BitBlt(Picture2.hdc, 0, 0, stdW, stdH, picMask.hdc, 0, 0, vbSrcAnd)
'    mresult = BitBlt(Picture2.hdc, 0, 0, stdW, stdH, picImage.hdc, 0, 0, vbSrcInvert)
'    BuildIcon Picture2
'    SavePicture Picture2.Picture, App.Path & "/Frombmp.ico"
End Sub



Private Sub command1_Alternative()
    picImage.Line (0, 0)-(stdW - 1, stdH - 1), vbBlack, BF
    picMask.Line (0, 0)-(stdW - 1, stdH - 1), vbWhite, BF
   
    Dim mtransp As Long
      ' Area having the following color is to be left out
      ' as it is meant to be transparent
    mtransp = Picture1.Point(0, 0)
    Dim i, j
    For i = 0 To stdW - 1
        For j = 0 To stdH - 1
            If Picture1.Point(i, j) <> mtransp Then
                 picImage.PSet (i, j), Picture1.Point(i, j)
                 picMask.PSet (i, j)
            End If
        Next j
    Next i
    BuildIcon Picture2
    SavePicture Picture2.Picture, App.Path & "/Frombmp.ico"
End Sub



Private Sub command2_Click()
    On Error Resume Next
    Dim i, j
    Dim p, q
    
    Picture4.Picture = Picture3.Image
    
'--------------------------------------------------------
'NB This following is only a matter of variation, not a must.

'   Let us select the form's color as background color here
'   and replace the existing one with it.
'--------------------------------------------------------
    p = Picture4.Point(0, 0)
    q = Me.BackColor
      ' Paint the desired color as if backgound
    For i = 0 To stdW
         For j = 0 To stdH
              If Picture4.Point(i, j) = p Then
                   Picture4.PSet (i, j), q
              End If
         Next j
    Next i
    
'--------------------------------------------------------
'  Alternatively
'  To open the following, close above and uncomment API first
'--------------------------------------------------------

'    Picture4.FillColor = q
'    Picture4.FillStyle = vbFSSolid
'    mresult = ExtFloodFill(Picture4.hdc, 0, 0, p, 1)
'       'Another line is required only because the fill area
'       'is broken by the tip point of the flap of envelope.
'    mresult = ExtFloodFill(Picture4.hdc, stdW - 1, stdH - 1, p, 1)
'--------------------------------------------------------

    SavePicture Picture4.Picture, App.Path & "/Fromico.bmp"
End Sub



' To let you see it again and again.
Private Sub Command3_Click()
    Picture2.Picture = LoadPicture()
End Sub


Private Sub Command4_Click()
    Picture4.Picture = LoadPicture()
End Sub



Private Function CreateMask_viaMemoryDC(Pic1 As PictureBox, Pic2 As PictureBox) As Boolean
     On Error GoTo errHandler
     CreateMask_viaMemoryDC = False
     
     Dim dx As Long, dy As Long
     Dim hdcMono2 As Long, bmpMono2 As Long, bmpMonoTemp2 As Long
     
     dx = Pic1.ScaleWidth
     dy = Pic1.ScaleHeight
     
      ' Create memory device context (0 is screen, as we want the new
      ' DC compatible with the screen).
     hdcMono2 = CreateCompatibleDC(0)
     If hdcMono2 = 0 Then
         GoTo errHandler
     End If
      ' Create monochrome bitmap, of a wanted size
     bmpMono2 = CreateCompatibleBitmap(hdcMono2, dx, dy)
      ' Get a monohrome bitmap by default after putting in the
      ' above created bitmap into the DC.
     bmpMonoTemp2 = SelectObject(hdcMono2, bmpMono2)
      ' Copy bitmap of Pic1 to memory DC to create mono mask of the color bitmap.
     mresult = BitBlt(hdcMono2, 0, 0, dx, dy, Pic1.hdc, 0, 0, vbSrcCopy)
      ' Copy mono memory mask to a picture box, as wanted in this case
     mresult = BitBlt(Pic2.hdc, 0, 0, dx, dy, hdcMono2, 0, 0, vbSrcCopy)
     
      ' Clean up
     Call SelectObject(hdcMono2, bmpMonoTemp2)
     Call DeleteDC(hdcMono2)
     Call DeleteObject(bmpMono2)
     
     CreateMask_viaMemoryDC = True
     Exit Function
errHandler:
     MsgBox "MakeMask_viaMemoryDC"
End Function




Private Sub ExtractIconComposite(inPic As PictureBox)
    On Error Resume Next
    Dim ipic As IPicture
    Dim icoinfo As ICONINFO
    Dim pDesc As pictDesc
    Dim hDCWork
    Dim hBMOldWork
    Dim hNewBM
    Dim hBMOldMono
    
    GetIconInfo inPic.Picture, icoinfo
    hDCWork = CreateCompatibleDC(0)
    hNewBM = CreateCompatibleBitmap(inPic.hdc, stdW, stdH)

    hBMOldWork = SelectObject(hDCWork, hNewBM)
    hBMOldMono = SelectObject(hdcMono, icoinfo.hBMMask)
    BitBlt hDCWork, 0, 0, stdW, stdH, hdcMono, 0, 0, vbSrcCopy
    SelectObject hdcMono, hBMOldMono
    SelectObject hDCWork, hBMOldWork
    With pDesc
        .cbSizeofStruct = Len(pDesc)
        .picType = PICTYPE_BITMAP
        .hImage = hNewBM
    End With
    OleCreatePictureIndirect pDesc, iGuid, 1, ipic
    picMask = ipic
    Set ipic = Nothing
    
    pDesc.hImage = icoinfo.hBMColor
      ' Third parameter set to 1 (true) to let picture be destroyed automatically
    OleCreatePictureIndirect pDesc, iGuid, 1, ipic
    picImage = ipic
    
    ;DeleteObject icoinfo.hBMMask
    ;DeleteDC hDCWork
    Set hBMOldWork = Nothing
    Set hBMOldMono = Nothing
End Sub




Private Sub BuildIcon(inPic As PictureBox)
    On Error Resume Next
    Dim hOldMonoBM
    Dim hDCWork
    Dim hBMOldWork
    Dim hBMWork
    Dim ipic As IPicture
    Dim pDesc As pictDesc
    Dim icoinfo As ICONINFO

    BitBlt hdcMono, 0, 0, stdW, stdH, picMask.hdc, 0, 0, vbSrcCopy
    SelectObject hdcMono, bmpMonoTemp
    hDCWork = CreateCompatibleDC(0)
    
    With inPic
        hBMWork = CreateCompatibleBitmap(inPic.hdc, stdW, stdH)
    End With
    
    hBMOldWork = SelectObject(hDCWork, hBMWork)
    BitBlt hDCWork, 0, 0, stdW, stdH, picImage.hdc, 0, 0, vbSrcCopy
    SelectObject hDCWork, hBMOldWork
    
    With icoinfo
        .fIcon = 1
        .xHotspot = 16            ' Doesn't matter here
        .yHotspot = 16
        .hBMMask = bmpMono
        .hBMColor = hBMWork
    End With
    
    With pDesc
        .cbSizeofStruct = Len(pDesc)
        .picType = PICTYPE_ICON
        .hImage = CreateIconIndirect(icoinfo)
    End With
    
    OleCreatePictureIndirect pDesc, iGuid, 1, ipic
    
    inPic.Picture = LoadPicture()
    inPic = ipic
    bmpMonoTemp = SelectObject(hdcMono, bmpMono)
    ;DeleteObject icoinfo.hBMMask
    ;DeleteDC hDCWork
    Set hBMOldWork = Nothing
End Sub




Sub CreateTransparent(inpicSrc As PictureBox, inpicDest As PictureBox, _
          inTrasparentColor As Long)
    On Error Resume Next
    Dim mMaskDC As Long
    Dim mMaskBmp As Long
    Dim mTempMaskBMP As Long
    Dim mMonoBMP As Long
    Dim mMonoDC As Long
    Dim mTempMonoBMP As Long
    Dim mSrcHDC As Long, mDestHDC As Long
    Dim w As Long, h As Long
    
    w = inpicSrc.ScaleWidth
    h = inpicSrc.ScaleHeight
    
    mSrcHDC = inpicSrc.hdc
    mDestHDC = inpicDest.hdc
    
     ' Set back color of source pic and dest pic to the desired transparent color
    mresult = SetBkColor&;(mSrcHDC, inTrasparentColor)
    mresult = SetBkColor&;(mDestHDC, inTrasparentColor)
    
    ' Create a mask DC compatible with dest image
    mMaskDC = CreateCompatibleDC(mDestHDC)
    ' and a bitmap of its size
    mMaskBmp = CreateCompatibleBitmap(mDestHDC, w, h)
    ' Move that bitmap into mMaskDC
    mTempMaskBMP = SelectObject(mMaskDC, mMaskBmp)
    
    ' Meanwhile create another DC for mono bitmap
    mMonoDC = CreateCompatibleDC(mDestHDC)
    '  and its bitmap, a mono one (by setting nPlanes and nbitcount
    '  both to 1)
    mMonoBMP = CreateBitmap(w, h, 1, 1, 0)
    mTempMonoBMP = SelectObject(mMonoDC, mMonoBMP)
    
    ' Copy source image to mMonoDC
    mresult = BitBlt(mMonoDC, 0, 0, w, h, mSrcHDC, 0, 0, vbSrcCopy)
        
    ' Copy mMonoDC into mMaskDC
    mresult = BitBlt(mMaskDC, 0, 0, w, h, mMonoDC, 0, 0, vbSrcCopy)

    'We don't need mMonoBMP any longer
    mMonoBMP = SelectObject(mMonoDC, mTempMonoBMP)
    mresult = DeleteObject(mMonoBMP)
    mresult = DeleteDC(mMonoDC)
    
    'Now copy source image to dest image with XOR
    mresult = BitBlt(mDestHDC, 0, 0, w, h, mSrcHDC, 0, 0, vbSrcInvert)
    
    'Copy the mMaskDC to dest image with AND
    mresult = BitBlt(mDestHDC, 0, 0, w, h, mMaskDC, 0, 0, vbSrcAnd)
    
    'Copy source image to dest image with XOR
    BitBlt mDestHDC, 0, 0, w, h, mSrcHDC, 0, 0, vbSrcInvert
    'Picture is there to stay
    inpicDest.Picture = inpicDest.Image
     
    ' We don't need these
    mMaskBmp = SelectObject(mMaskDC, mTempMaskBMP)
    mresult = DeleteObject(mMaskBmp)
    mresult = DeleteDC(mMaskDC)
End Sub



' Last clear up
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    SelectObject bmpMono, bmpMonoTemp
    ;DeleteObject bmpMono
    ;DeleteDC hdcMono
End Sub



Ответить

Номер ответа: 12
Автор ответа:
 Softer



ICQ: 203660381  

Вопросов: 29
Ответов: 205
 Web-сайт: hware.org.ua
 Профиль | | #12
Добавлено: 24.07.05 06:47
@sne, спасибо! Это то что мне было нужно!

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам