Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to import an image to excel. I did import the image, however I want the image's background to be transparent. When I tried this code:

bm_dest.MakeTransparent(bm_dest.GetPixel(1, 1))

the background image changed from white to grey.

Here's the whole code:
VB
Dim oRng1 As Microsoft.Office.Interop.Excel.Range
       Dim F1 As Image
       Dim bm_source As Bitmap
       Dim scale_factor As Single = 0.175
       oRng1 = xlWorkSheet.Range("A8")
       F1 = SignaturePictureBox.Image
       bm_source = New Bitmap(F1)
       Dim bm_dest As New Bitmap(CInt(bm_source.Width * scale_factor), CInt(bm_source.Height * scale_factor))
       Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
       gr_dest.DrawImage(bm_source, 0, 0, bm_dest.Width + 1, bm_dest.Height + 1)
       bm_dest.MakeTransparent(bm_dest.GetPixel(1, 1))
       Clipboard.SetDataObject(bm_dest, False)
       xlWorkSheet.Range("A43").Select()
       xlWorkSheet.PasteSpecial(Format:="Bitmap")
       bm_dest.Dispose()
       bm_source.Dispose()
       gr_dest.Dispose()


P.S. I am a beginner with VB
Posted
Updated 17-Jun-15 2:02am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900