How to replace image of a picture shape in PowerPoint? - vba

Is there any way to replace the image of an existing picture shape in PowerPoint from code?
Thanks

If it's a linked image, either overwrite the linked image file with a new file or point the link at a new file.
Or if the shape is picture filled, you can fill it with a different picture instead. That can distort the picture if its proportions don't match the shape's proportions; instead, you can change the aspect ratio of the shape to match that of the picture if need be.
To change the picture fill, assuming a reference to the shape in osh:
With osh.Fill
.UserPicture ("C:\path\to\picture.jpg")
End With
To work out the size of the picture so you can adjust the shape to it, you can either use external image processing software or insert the picture into PPT, giving -1 for height and width parameters and pick up the .Height and .Width of the newly inserted picture, then delete it.
Or insert a new picture, pick up the old picture's size/position/other proprties and apply them to the new picture, delete the old picture, move the new one to the old one's Z-order.

Related

vb.net- How to make any picture in a picture box round in shape

I am making an application in vb.net that has a good user interface, including the your account icon that includes a picture box. My question is that how can i make that image in the picture box round in shape?
Like This:
https://drive.google.com/open?id=1rUBq68ULDkTiFFv2uEiV_oQIh3wQIfhd
I wouldn't normally provide code for a question that doesn't show an attempt but there are a few steps in the answer and it was easier to just write the code myself than explain them. E.g.
'Get the original image.
Dim originalImage = PictureBox1.Image
'Create a new, blank image with the same dimensions.
Dim croppedImage As New Bitmap(originalImage.Width, originalImage.Height)
'Prepare to draw on the new image.
Using g = Graphics.FromImage(croppedImage)
Dim path As New GraphicsPath
'Create an ellipse that fills the image in both directions.
path.AddEllipse(0, 0, croppedImage.Width, croppedImage.Height)
Dim reg As New Region(path)
'Draw only within the specified ellipse.
g.Clip = reg
g.DrawImage(originalImage, Point.Empty)
End Using
'Display the new image.
PictureBox2.Image = croppedImage
That will create an elliptical image with the same width and height as the original. If the original is square then the final will be circular. If you want a circle regardless of the aspect ratio of the original then you'll have to manipulate that in the appropriate manner.
Though i see that you already found out the solution to your question, however here's a very simple workaround.
Assuming, your project is in WinForms, and you are using Picture Box control. The easiest way to achieve the round-image-look is to set the Image property of the PictureBox to an image that is round-shaped and is blank/transparent in the middle and white on the outside. Then , whatever image you set as a BackgroundImage , it will appear round-ish.
Here's a sample round-transparent image for you which you can set as Image(make sure to set SizeMode to stretch) and then set any picture as BackgroundImage.

Inserting images automatically on slides referencing model #? MICROSOFT POWERPOINT

I have about 100 slides here on powerpoint that look like this:
Slide example screenshot
I need to insert an image into the text box on each slide with the sizing of
height = 5, width = 3.64
and positioning of:
Horizontal = 6" / Vertical = 1.2" (Both from top left corner)
For good measure, here are all of the image format settings:
Image format settings screenshot
The image files are the same as the model number, such as MHS1306.jpg.
Is there any way to use a macro to automatically reference the model number, insert the corresponding image, and then resize it to the correct size?
All of the images are in the same folder.
The image just needs to be in that position, the text box isn't important, just shows where the image should go.
I am very new to VBA and scripts, and basically know nothing about it yet, so I would appreciate any help.
Thanks.

How to move a rotated shape to a specific location in excel 2010 using vba

I've written some VBA code that automatically creates a chart. One of the axes on this chart doesn't use normal labels but a graphic. I've stored the graphic as an image and I use the .Copy and .Paste methods to get a copy of this image onto the chart.
Here is where it gets confusing. I need to rotate the image to get it aligned with the axis (using the .rotation property). But when I set the .top and .left properties the shape doesn't end up where I would expect. In fact setting the properties to 0 and 0 doesn't do what I would expect either. I've tried changing the order of the way I set the properties on the image object but it only appears in a different (wrong) location.
I'm sure I'm missing some vital aspect of how VBA/Excel is placing the object relative to what I'm setting the top and left properties to. Basically my goal is to make the image on the left side of the chart with the same width as the plot area's height (since the image is rotated I theorize this will make it the same size).
This code does not work:
Sheets(ImageSheet).Shapes("agreement").Copy
c.Chart.Paste
c.Chart.Shapes(1).Rotation=270
c.Chart.Shapes(1).width = c.Chart.PlotArea.height
c.Chart.shapes(1).left = 5
c.Chart.Shapes(1).top = c.Chart.PlotArea.top
I've also tried this code
c.chart.Shapes(1).top = c.chart.PlotArea.top + c.Chart.PlotArea.height
because I thought maybe it was calculating the "top" as the upper-left corner of the image object when it is not rotated (rotating 270 degrees makes this point in a place where it should align with the bottom of the plot area). But that doesn't do what I expected either.
The image is a skinny rectangle that acts as a label for the axis. The chart will end up being laid out like this: http://imgur.com/NrSXR and the axis label image would be something like this http://imgur.com/08EWU
What am I missing here?
Is it possible for you to align your chart into a position where the shape could rest align/on a cell?
IF YES then here is a suggestion:-
You could position shape into a cell. Then adjust the size to what you need. And rotate.
Then change its bring forward property be shown on the Chart.
Next Group Chart and the Shape
PS: I recorded a macro. However it's best if you could show us what your the exact picture (=how your sheeet/chart/image should look like) of your question.
I ended up rotating and resizing the image before copying and pasting to the chart and then positioning it. I had to use the IncrementLeft and IncrementTop methods rather than setting the left and top properties directly because that did not have the desired effect.
When doing the paste into the chart the object always ended up in the upper left hand-corner so I could increment to the left by the small amount I wanted as a margin I wanted there and increment the top by the value of PlotArea.top to align it with the plot area.
I was also surprised that when creating the copy of my image it retained the "name" i referred to it as when I copied it to the new sheet and chart. This was especially useful for positioning the image once it was on the chart.
I also needed execute this code at the very end of my procedure, after everything else had been positioned and aligned, or when I positioned the data labels for one of my series they wouldn't appear correctly.
Here is the code that I ended up using:
'make a copy of the label image and refer to it with a variable for convenience
Sheets(ImageSheet).Shapes("maturity").Copy
i = Sheets(ImageSheet).Shapes.Count
Sheets(ImageSheet).Paste
Dim axisImage As Shape
Set axisImage = Sheets(ImageSheet).Shapes(i + 1)
'rotate and resize the image
With axisImage
.Rotation = 270
.width = c.Chart.PlotArea.height
End With
'cut and paste the new image to the chart
axisImage.Cut
c.Chart.Paste
'position it in the chart using IncrementTop and IncrementLeft because setting the properties directly does not have the desired effect
c.Chart.Shapes("maturity").IncrementTop c.Chart.PlotArea.top
c.Chart.Shapes("maturity").IncrementLeft c.Chart.PlotArea.left - c.Chart.Shapes("maturity").height

VB .NET picture GetPixel & SetPixel: Include alpha?

I am trying to use GetPixel and SetPixel to copy the contents of one picture to another (I know there are other methods to do so, but there are reasons I want to try this ;D)
Anyway, the pictures are .png images, so they include transparency settings.
But for some reason, it seems like when I use GetPixel & SetPixel to put one image over another, it seems the second image completely replaces the other one. I mean, it seems the transparency settings are not respected when I use GetPixel & SetPixel.
Both images have the same size. Both have transparent areas.
Before calling SetPixel() you need to call MakeTransparnet(). Here's some code that copies the contents of the first pixel in an alpha-image onto another image and retain's the first image's alpha channel:
Using img1 = New Bitmap("c:\Users\Owner\Desktop\1.png")
PX = img1.GetPixel(0, 0)
End Using
Using img2 = New Bitmap("c:\Users\Owner\Desktop\2.png")
img2.MakeTransparent() '//Sets the transparent value and converts the image to Format32bppArgb
img2.SetPixel(0, 0, PX)
img2.Save("c:\Users\Owner\Desktop\3.png")
End Using

itextsharp: getting height of image

i need to add a data table right after an image on a PDF in vb.net
last_pos=jpg2.height
datatable.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)
unfortunately this is the output:
i highlighted broccoli, buckwheat, butter, cabbage. these are all part of a data table that is supposed to go after the bottom SEVERE word because the entire thing that you see is one image called jpg2
alt text http://img710.imageshack.us/img710/3661/fullscreencapture121520.png
If you are using .ScalePercent to stretch the image (I suspect this based on some of your previous posts), the actual dimensions of the image object do not change after you have applied .ScalePercent to it. To get the displayed height of the image, you will have to:
jpg2.Height * my_scalefactor