Saving image in Excel workbook - image

I am building an Excel 2010 workbook that will use images to represent boards plugging into slots. Currently, I am using LoadPicture to pull the image from the disk to use on the worksheet. But when I send the workbook to somebody, they get error messages unless I send the image files also. Is there a way to actually have the image files be a part of the workbook file so that I don't have to package the image files with the workbook?
Thank you for your help!

When you get the picture, make sure the picture is saved with the document and not just a link:
Sub GetThePicture()
ActiveSheet.Shapes.AddPicture _
"c:\TestFolder\sample.jpg", _
msoFalse, msoTrue, 100, 100, 70, 70
End Sub

Related

Access 2016 restrict picture size to 600x800

I am building a database and came across an issue that I need help in resolving. This database the customer wants to be able to link pictures to specific records. I have it so the pics are not OLE objects but links to a picture folder that will be on their network drive...So essentially the picture will be a hyperlink to the file path....
My question is does anyone know I way I can have the database reformat the picture automatically to 600 x 800 size, to help save space? We all know if I don't force the DB to do it for them it will not happen and potentially eat up valuable space, as this DB is expected to get quite large. So I would like to keep the picture folder as small as possible, giving the database more room.
You can use the WIA libary as shown in VBA – Resize Image like this:
Function ResizeImageTo600x800(ByVal PathToImage As String, ByVal PathToResizedImage As String) As Boolean
Dim WiaImgFile As Object 'WIA.ImageFile
Set WiaImgFile = CreateObject("WIA.ImageFile")
With CreateObject("WIA.ImageProcess") 'WIA.ImageProcess
.Filters.Add .FilterInfos("Scale").FilterID 'Add Scale Filter to ImageProcess
.Filters(1).Properties("MaximumWidth") = 600 ' Set Width to 600px
.Filters(1).Properties("MaximumHeight") = 800 'Set Height to 800px
'.Filters(1).Properties("PreserveAspectRatio") = False ' uncomment if AspectRatio should not be preseved
WiaImgFile.LoadFile PathToImage ' Load Image
.Apply(WiaImgFile).SaveFile PathToResizedImage ' Apply Filter and save resized Image
ResizeImageTo600x800 = True
Set WiaImgFile = Nothing
End With
End Function
Usage:
If ResizeImageTo600x800("\\path\to\image", "\\path\to\resized\image") then
Msgbox "ResizeImageTo600x800 successful!"
End If
Or:
ResizeImageTo600x800 "\\path\to\image", "\\path\to\resized\image"
Depending on your image types, you may also increase the compression of your image to save space. WIA should support this too (with the Convert Filter and its Quality Property).

Save image in picturebox with vb6

i used vb6. i want to modify a picture in picturebox1 and process make that picture in picturebox2. so i want to save picture in .picturebox2. can you help me? i found this code but it didnt work
Private Sub save_Click()
picturebox2.Picture = bitmap
picturebox2.Picture = ("c:\\image\\image1.jpg")
End sub
End Sub
You need to use the SavePicture statement. This will probably save your graphic as a bmp file, not as a jpg file as your code snippet suggests.
SavePicture picturebox2.picture, "filename.bmp"
See https://msdn.microsoft.com/en-us/library/aa445827(v=vs.60).aspx
In VB6.0 you can convert BMP to JPG using additional code.
See my BMP2JPG sample project in my web site:
http://nuke.vbcorner.net/Projects/VB60/VB60variousprojects/tabid/79/language/en-US/Default.aspx#bmp2jpg
HTH

Loadpicture giving Runtime-error 481: Invalid picture

I have a project which copy varbinary(max) image data from sql server to msaccess ole object and when I am trying to bind that images to image control of VB6 its giving Runtime-error 481: Invalid picture, also I tried saving those msaccess images and they are getting saved fine but when I am trying to load those images in image control they are giving same error, following is my code and attach is my image file
Private Sub Form_Load()
Image1.Picture = LoadPicture("f:\tttt111.jpeg")
End Sub
Following is the url to download image
https://wetransfer.com/downloads/e2d4a91143507b3522bdd6632d69aa8b20161214051703/ae44f7
That is because you are using a PNG file and that is not supported by VB6. The supported formats are Bitmap, Icon, Cursor, Metafile, JPEG, and GIF. More info here...
Try converting the image to JPEG and it'll work.
We've had WIA 2.0 for a long time now. Here the database data is simulated by reading the file bytes:
Option Explicit
'
'Reference to: Microsoft Windows Image Acquisition Library v2.0
'
Private Sub Form_Load()
Dim F As Integer
Dim Bytes() As Byte
'Get data into Byte array:
F = FreeFile(0)
Open "oBSkm.png" For Binary Access Read As #F
ReDim Bytes(LOF(F) - 1)
Get #F, , Bytes
Close #F
With New WIA.Vector
.BinaryData = Bytes
Image1.Picture = .Picture
End With
With New WIA.ImageFile
.LoadFile "oBSkm.png"
Image2.Picture = .FileData.Picture
End With
End Sub
Preinstalled as part of Windows Vista and later. Was once available as an SDK with documentation and a redist version to be installed into Windows XP SP1 or later but no longer provided by Microsoft. You snooze, you lose.
I had same issue but I am happy I found working solution. The source of this issue for me was image dimensions was too large than image control I was trying to place image on, So All I had to do is change the image dimensions from 500 X 500 to 200 X 200 and error 481 in vba excel (invalid picture) was resolved.

Formatting Image in Excel using win32com.client

I am creating an excel spreadsheet using pythons win32com module excel client. I wanted to add a logo to my excel spreadsheet report. So far I have managed to add the picture:
# Set a variable to an empty excel instance
excel = win32com.client.Dispatch("Excel.Application")
# Initialize a workbook within excel
book = excel.Workbooks.Add()
# Create sheet in book
sheet = book.Worksheets(1)
sheet.Pictures().Insert(r"G:\logos\Logo.jpg")
I've been pouring through the web and I cannot seem to find a way to access the position properties of the picture to move to it a particular place, nor can I find out how to access the sizing properties. Is there a help doc out there that has some examples that I cannot seem to find?
Try
cell = sheet.Cells(1,1)
pic = sheet.Pictures().Insert(r"G:\logos\Logo.jpg")
pic.Left = cell.Left + 20
pic.Top = cell.Top + 30
which will position your picture at 20 pixels right and 30 down from top left corner of given cell.
Regarding help, my reference is search for "excel interop " such as "excel interop range" or "excel interop picture" which leads to Picture object docs.

get format of image and videos in visual basic

I have some images and videos in my powerpoint presentation. Depends of what format have each one (jpg, mp3, jpeg,...) I want it to make a different thing so I need to know what kind of file is it. Is there anything in Visual Basic to make it?
EDITED
I want to difference the images and videos supported by iPad with the ones that are not supported. That is why I need to know the format of them.
EDIT: to state it clear- solution below works only with shapes which are linked to files!
Function WhatTypeOfMedia(SHP As Shape)
Select Case Right(SHP.LinkFormat.SourceFullName, 4)
Case ".jpg", "jpeg"
WhatTypeOfMedia = "Picture type"
Case ".wav", ".mp3"
WhatTypeOfMedia = "Music type"
'... end other possible types put here
End Select
End Function
To make a test run for 1st slide of active presentation try this code:
Sub Take_format_Linked()
On Error Resume Next 'required for these files which are not linked
Dim SHP As Shape
For Each SHP In ActivePresentation.Slides(1).Shapes
'1st check if format is linked- best option:
If Len(SHP.LinkFormat.SourceFullName) > 0 Then
If Err.Number = 0 Then
'if so, let's call function
Debug.Print WhatTypeOfMedia(SHP)
'here you can do what you want based on function result
Else
Err.Clear
End If
End If
Next
End Sub
As a result you get information in Immediate window which shape is which type. You could use that types to run what you need in main sub.
In that simple idea I kept On Error Resume Next to avoid error if Shape is not linked.
As has been pointed out, you can get the file types for linked files, but there's no way to get them for embedded files. However, if you don't need to do it in VBA or can manipulate ZIP files in VBA, open the PPTX as a zip and look for the media folder. There you'll find any embedded files (pictures, sounds, movies).
They may not be in the same format as they originally were in; PPT sometimes converts images when it imports them. But that shouldn't be an issue considering what you're after.

Resources