VBA Excel 2010 CreateObject ExtendedProperty get image width attribute - vba

I'm using similar kind of functions to get some property attributes like Filename, bit depth, dimensions, size etc by using some vba code. The last line of that function would be something like the following:
PicSize = CreateObject("Shell.Application").Namespace(vPth2).Parsename(sPic2).ExtendedProperty("size")
Now, I want to get the height and width of that image file. I've put height and width in the ExtendedProperty attribute value but it's not giving me the height and width of that file.
Note that, in the property dialog box of that image file, in the summary tab, it is showing Bit depth but putting this did not work. Then I put bitdepth and it worked successfully. The names are not case sensitive.
Okay! Now all I want to get the height and width of that selected image file. How can I do that? I mean what to put inside ExtendedProperty() to get height and width.
An early reply with solution would be highly appreciated.

Can't help with why Height and Width don't work, but Dimensions seems to work, returns a string like ?493 x 376?

I suggest the work around method
replace size in your code
PicSize=CreateObject("Shell.Application").Namespace(vPth2).Parsename(sPic2).ExtendedProperty("size")
to Dimensions
you will get something like ?493 x 376?
now declare
a string t = "?493 x 376?"
'search the index of "x"
search_x = InStr(t, "x")
'we would got width and height by
width = Mid(t, 2, search_x - 2)
height = Mid(t, search_x + 2, Len(t) - 8)
It is unknow why but I found that start at "2" in width and "-8" in height like that would give a number

Related

Is there a way to set the dimensions of a paragraph in itext7?

Trying to set the height along with setting the rotation on a Paragraph object results in the following error:
ERROR c.i.layout.renderer.BlockRenderer - Rotation was not correctly processed for ParagraphRenderer
Also, the height is sent to infinity resulting in an apparently empty page which I'm not sure if it's the expected behavior or not.
If I don't set the height, the text shows up rotated (which is what I want). But my task is to place the text at certain coordinates with certain dimensions and rotation. The placement is fine, but not being able to set the height results in assigning the rotation points to the wrong values and in turn displacing the final position of the text.
Paragraph paragraph = new Paragraph(text);
paragraph.setHeight(height);
paragraph.setMargins(0, 0, 0, 0);
paragraph.setProperty(ROTATION_POINT_X, x);
paragraph.setProperty(ROTATION_POINT_Y, y);
paragraph.setProperty(ROTATION_ANGLE, asFloat(toRadians(rotation))));
document.add(paragraph);
Setting the margins to 0 doesn't seem to have any influence either. The text looks to keep some sort of margin anyway.
So is there a way to control what the dimensions of the object displayed are? I could also settle for a way to make the rotation pivot from the center of the object.
You should set both width and height at the same time for rotated objects.
Here is an example code:
Paragraph paragraph = new Paragraph("Hello world");
paragraph.setWidth(200);
paragraph.setHeight(20);
paragraph.setBackgroundColor(ColorConstants.RED);
paragraph.setMargins(0, 0, 0, 100);
paragraph.setProperty(ROTATION_POINT_X, paragraph.getWidth().getValue() / 2);
paragraph.setProperty(ROTATION_POINT_Y, paragraph.getHeight().getValue() / 2);
paragraph.setRotationAngle(Math.PI / 180 * 45);
document.add(paragraph);
Visual result:

iText Vertical Alignment in Text inside a Canvas isn't working

I'm trying to set my text which is inside a canvas to get vertically aligned with VerticalAlignment.BOTTOM property value, but whatever I put doesn't change the visual result.
retangulo = New iText.Kernel.Geom.Rectangle(122, AlturaPag - 208, 235, 27)
PdfCanvas = New iText.Kernel.Pdf.Canvas.PdfCanvas(page).SetLineWidth(1).Rectangle(retangulo).Stroke()
canvas = New iText.Layout.Canvas(PdfCanvas, retangulo)
texto = (New iText.Layout.Element.Text(Npagador).SetFontSize(11).SetBold)
' VerticalAlingment = BOTTOM \/
paragrafo = (New iText.Layout.Element.Paragraph().Add(texto).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.BOTTOM))
canvas.Add(paragrafo)
You are trying to align the contents of the paragraph to the bottom of the paragraph itself, and the paragraph when laying itself out simply uses the minimal necessary height, so whatever alignment (bottom or top) you set, the result it just the same simply because paragraph packs itself to the minimal height.
To make sure setVerticalAlignment has an effect, you need to give the paragraph more vertical space by setting its height. Here is an example where I set paragraph height to match the height of the canvas you add it to, since it's the only element in the canvas. I also set the margins of the paragraph to zero so that you don't get additional spacing around the text.
The code is in Java but you will be able to convert it back to VB.NET as easily as I converted your code to Java:
Paragraph p = new Paragraph().add("Test").setTextAlignment(TextAlignment.LEFT)
.setVerticalAlignment(VerticalAlignment.BOTTOM).setHeight(retangulo.getHeight());
p.setMargin(0);

how i can measure width of text entity in Eyeshot Vb.net?

I want to measure text width in Vb.net. Just like i have a text entity, i can get or set the text height but unable to get the text width.Just like the text in the code, i want its width , i have set its height to be 0.25 in the constructor.
Dim a As Text
a.TextString = "Ahmad"
a.Height = 0.25
a.Plane = Plane.ZX
a.InsertionPoint = New Point3D(xMinGlobal - 2.5, 0, 1.5)
You can check the BoxSize property of the entity.
If it's Nothing, try calling the Regen() method or adding the text entity to the scene.

Text Formatting To Avoid Overwritting

I already saw this question but it doesn’t help me.
The problem is that I can write the text to the PDF file, but if I do that with a new gfx.DrawString it put the second text on the first...
like this....
Here is my code I used to set a new line:
gfx.DrawString(lbname.Text + " " + lbnamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
gfx.DrawString(lbvorname.Text + " " + lbvornamei.Text, font, XBrushes.Black, new XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.TopLeft);
I think it has something to do with the numbers in the first argument (new XRect(0, 0,) but it is unclear how to set them.
I can't remember which parameter does which, but this will help you discover for yourself:
Set one of the numbers to 20 on one of the pieces of text; observe the effect. Then change it back and change a different number; observe the effect.
An XRect has the four parameters x, y, width, height. x is the position from the left, y is the position from the top.
Width and height have no effect as long as XStringFormats.TopLeft is used. Therefore it is enough with the code shown above to increment y to draw text in a new line.
Width must be set to have text that is right-aligned or horizontally centered.
Height must be set to have text that is bottom-aligned or vertically centered.

Color.ToArgb relation between 5046311 and 14221235?

the form backcolor is 14221235 , but when i set the customcolor in colordialog to equal the form backcolor, it sets it to 5046311 !!! what is the problem?
this is how i am getting the background color:
get_background = Str(Abs(Form1.BackColor.ToArgb))
the reason i am turning it into a string is because i will feed it into a string which has "32498239, 234234234, 23423234, 32234432432, 423324234"
then i take this string and put it in customcolors like this. btw this piece of code works fine:
Dim numberStrings = My.Settings.mytext1.Split(","c).Select(Function(x) x.Trim())
ColorDialog1.CustomColors = numberStrings.Select(Function(x) CInt(x)).ToArray()
a user below mentioned that toargb takes into account the opacity. this is an excellent point indeed, and i want to clarify that i DO NOT need the opacity. how would i do toargb without taking into opacity?
this is what you want
Microsoft.VisualBasic.RGB(Me.BackColor.R, Me.BackColor.G, Me.BackColor.B).ToString
The 32-bit result from .ToArgb() contains not just the three visible color components (red, green and blue) but also the alpha component, which is essentially opacity. This is a pure guess on my part, but I think the ColorDialog is just used for picking RGB values, so when you set the color to the form's BackColor, the dialog just ignores the alpha component (or sets it to zero), which is why you end up getting a different number from the .ToArgb() method.
Note: this is just speculation on my part. It would help if you posted a code sample that demonstrates the specific problem.
I don't really understand the question. You want to set the custom color dialog CustomColor property to (the form's backcolor) r + g + b components? Not sure why you would do that, you can always just get the form's backcolor, set the Alpha value to 255 and then set the result to the CustomColor property:
Color c = Color.FromArgb( 255, form1.BackColor );
myColorDlg.CustomColor = c;
Or just use form1.BackColor.ToArgb() & 0xFFFFFF (if you want the integer value).
If you are asking for ARGB (A = Alpha) then you are asking for the opacity information. Instead you could use the R, G, B Properties of Color Independently.
You could use Color.FromArgb(255, me.BackColor).ToArgb() in order to get the ARGB value of the same color with 100% opacity.
To highlight how to pass the same colour (Using Fredou's answer) from a colorDialog to set a pie chart segment colour, one which is a .Net embedded chart and the other an Excel chart:
embchartPie.Series(0).Points(Index).Color = ColorDialog1.Color
With ColorDialog1.Color
xl_Pie_Chart.SeriesCollection(1).points(Index + 1).format.fill.forecolor.rgb = RGB(.R, .G, .B).ToString
End With