Save image in picturebox with vb6 - 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

Related

Scale / Resize StdPicture in VB6

I have looked far and wide and reached the end of my wits trying to figure out how to do this. I have looked on XtremeVBTalk.com and the rest of the internet on how to resize a damn StdPicture!
Does anyone know how to do this? Is this even possible?
Thank you so much in advance. I desire not to use any type libraries etc. so if that is offered in a solution I don't think I will be able to use it.
I'm not using A picturebox control at all.
Say I have the following function header, and an StdPicture is passed in:
Private Function EncodeImageToBase64(ByRef Image As StdPicture) As String
I then have the following declarations where I intend on encoding the StdPicture to base64:
Dim xmlDoc As DOMDocument60
Dim xmlNode As MSXML2.IXMLDOMElement
Dim bColor() As Byte
Dim bMask() As Byte
Dim bImage() As Byte
Dim lCrcTable() As Long
Dim lWidth As Long
Dim lHeight As Long
EncodeImageToBase64 = vbNullString
If Image Is Nothing Then
Exit Function
End If
Call CRCTable(lCrcTable)
Call Icon2Arrays(Image, bColor, bMask, lWidth, lHeight)
If Not CreatePngByteArray(bImage, lWidth, lHeight, bColor, bMask, lCrcTable) Then
Debug.Assert False
Exit Function
End If
However, before calling that, I want to cut the image's width and height in half. How can I do so? CreatePngByteArray only supports 16x16 PNGs and I am using 32x32, so I'd like to cut them down in order to pass the asserts they have.
OK, I spent quite some time that I didn't really have on this one, because I didn't know the answer to begin with, but I was still interested in finding out what the potential solution was.
The following answer is my understanding of what you are trying to do, but may not be the answer to the question itself, so it could very well be considered wrong.
So, here's what I came up with. You will need to use an IPictureDisp object instead of an StdPicture object. You will also need to use a PictureBox control, even if you don't really want to.
Create a new project. Add a form, or open an existing one if one is provided. Set the ScaleMode of the form to pixels. Add a PictureBox control on the form. Set the AutoRedraw property of the PictureBox control to 'True', the BorderStyle property of the control to 'None', and the Height and Width properties of the control to 16 pixels each. Add the following code to the form, and modify the location and type of the image that you want to resize, and then the location to save it to:
Private Sub Form_Load()
Dim TestPic As IPictureDisp
Set TestPic = LoadPicture("C:\Users\Your Name\Desktop\image.gif")
With TestPic
.Render Picture1.hDC, 0, 16, 16, -17, 0, 0, .width, .height, 0
End With
SavePicture Picture1.Image, "C:\Users\Your Name\Desktop\image2.bmp"
End Sub
The image can start with any of the types that Visual Basic 6 supports (.bmp, .cur, .gif, .ico, .jpeg or .jpg, and .wmf), but must always be saved in bitmap format. Please note that Visual Basic 6 does not support PNG file formats at all, so you will not be able to use any VB6 functions to open PNG files or create them.
I would be interested in other solutions that other people come up with.
Edit: Fixed dimensions.
Do you mean inside the PICTUREBOX control or inside an IMAGE CONTROL? Because If I remember correctly it has a STRETCH property which autofits the image to the container
#Zaf Khan beat me to it. I have something similar where I have a PictureBox. Under behaviour I have SizeMode set to StretchImage then when I load an image like so
LoadWebImageToPictureBox(ImagePreview, SelectedFile)
it auto fits.

Can you include a Jpeg or any image onto an excel form

not sure if this is possible can you add a jpeg or another image to a form created in the vba section in excel? If so would anyone know how to go about doing this...
You are looking for the UserForm object, which has a picture property. There's a bit of info here on how to paste an image in a User Form control which you may find helpful. Best of luck!

Load Picture to Microsoft Access 2010 Ribbon from Table

I'm working with Access 2010's new ribbon feature, and I'm trying to figure out the simplest way to load an image to the ribbon from a table. I know that I could do this by using a GDI API function, but from what I can see the code looks convoluted and appears to utilize extra dlls that I would just as well avoid calling if I don't need to. I also know that I could create a control on a form, load the image to the form, and then load the image from the form to the ribbon image variable. While using the form is doable, it seems sloppy. Eventually, I will resort to one of the two preceding methods if I have to, but it just seems like there should be some simple way to load an image from a table directly into an image variable for the ribbon.
One thing to note is that I'm willing to use whatever image format is easiest. These icon files are very small and so I'm not concerned about file size and I also don't care whether or not they are capable of transparency. So if there's a method that only works with bitmap file types that is fine with me.
Here's the code I have for the button in the ribbon XML:
<button id="CCTrans" label="Credit Card Trans." getImage="GetMnuIcn" onAction="=OpenCCTrans()" />
And here's the code I have for retrieving the image:
Sub GetMnuIcn(control As IRibbonControl, ByRef Image)
Set Image = DLookup("Img", "LtblImg", "Lbl=""" & control.ID & """")
End Sub
I've tried storing the image both as an OLE Object and as an attachment. Either way, when I try to retrieve it, it gives me the error "Type Mismatch". For simplicity, I've been storing it as a bitmap, but I also tried .gif and .png in my first attempts.
Note: Apparently the ribbon icons are IPictureDisp objects. If I can just figure out how to load an image from a table into one of those object types, I should be able to use it for the ribbon.
Also, there's a lot of good information on Microsoft's website, but I haven't been able to piece it together into a solution yet. Here's a link: http://msdn.microsoft.com/en-us/library/bb187398.aspx
Well after tedious days of trying to find a better solution, I'm forced to pick between what I feel are various mediocre approaches. I really wanted to just load it directly into a variable, but the only method for doing that requires references to a bunch of dlls and has code that is pretty complicated. To avoid any extra dependencies and to keep my code simpler, I decided to go the route of assigning the table containing the attached images to a form, opening that form in hidden mode and then assigning the picture variables from the form.
For some reason the code that I saw elsewhere that loaded the pictures on demand via this method caused my program to crash and so I had to load the pictures into variables when the program opened and then have the menu bar set the icons from those variables when the menu is selected.
My code is as follows:
Dim Icn(15) As IPictureDisp, IcnLbl(15) As String
Function SetMnuIcn()
Dim Img As Recordset, i As Byte
DoCmd.OpenForm "frmImg", acNormal, , , acFormReadOnly, acHidden
Set Img = Forms!frmImg.Recordset
While Not Img.EOF
i = i + 1
Set Icn(i) = Forms!frmImg!Img.PictureDisp
IcnLbl(i) = Img!Lbl
Img.MoveNext
Wend
DoCmd.Close acForm, "frmImg", acSaveNo
End Function
Sub GetMnuIcn(control As IRibbonControl, ByRef Image)
Set Image = Icn(GetAryLoc(IcnLbl, control.ID, 15))
End Sub
Function GetAryLoc(varValues As Variant, varMatch As Variant, NumOfValues As Integer) As Integer
Dim i As Integer
For i = 1 To NumOfValues
If varValues(i) = varMatch Then GetAryLoc = i
Next
End Function
Note: To ensure that the icons have been loaded prior to when they are needed, I specified SetMnuIcn to run on ribbon load:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="=SetMnuIcn()">

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.

how to extract list or bullet details from .pptx or .ppt file using c#

I am using Microsoft office Interope assembly to extract features from .pptx and .ppt files using c#. I was able to extract details about shapes, animations but not able to extract details about which types of bullets ppt or pptx consists of or which slide contains bullets etc.
Please help me finding this.
Thanks in advance.
In VBA, you'd do something like this to examine the bullets on slide 1
Dim oSh As Shape
Dim x As Long ' Integer in C#?
For Each oSh In ActivePresentation.Slides(1).Shapes
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
With .TextFrame2.TextRange
For x = 1 To .Paragraphs.Count
Debug.Print .Paragraphs(x).ParagraphFormat.Bullet.[Various properties]
Next
End With
End If
End If
End With
Next
Look at the code in the PPT VBA editor. When you type the dot after Bullet above, intellisense will show you the available properties.
There are a few ways. In the code below, you can see the properties of the text that you can access in your program:
ppTextBox.TextFrame2.TextRange.ParagraphFormat.Bullet.Type =
Office.MsoBulletType.msoBulletNumbered;
ppTextBox.TextFrame2.TextRange.ParagraphFormat.Bullet.Style =
Office.MsoNumberedBulletStyle.msoBulletAlphaLCParenBoth;
ppTextBox.TextFrame2.TextRange.ParagraphFormat.Bullet.StartValue = 4;
ppTextBox.TextFrame2.TextRange.ParagraphFormat.Bullet.UseTextColor =
Office.MsoTriState.msoTrue;
ppTextBox.TextFrame2.TextRange.ParagraphFormat.Bullet.UseTextFont =
Office.MsoTriState.msoTrue;
where ppTextBox is a shape object, and note the use of TextFrame2 rather than TextFrame. You can interrogate the ParagraphFormat.Bullt.Type against the enumerated list Office.MsoBulletType to see which has been applied.
For more details, check this page for more details on text processing in powerpoint with C#.

Resources