Show image above SMFPlayer issue - c#

An image (Image class) is placed above a SMFPlayer (both elements are created in code-behind). Z-index of the image is the Z-Index of SMFPlayer + 1. The image is resized (adjusting the width) according to the playing progress of SMFPlayer.
videoPlayer = new SMFPlayer();
videoPlayer.Width = 1920;
videoPlayer.Height = 1080;
videoPlayer.Margin = new Thickness(1920, 0, 0, 0);
PlaylistItem item = new PlaylistItem();
Random r = new Random();
item.MediaSource = new Uri("video.wmv");
item.DeliveryMethod = DeliveryMethods.ProgressiveDownload;
videoPlayer.Playlist.Add(item);
videoPlayer.AutoPlay = true;
videoPlayer.AutoLoad = true;
videoPlayer.IsControlStripVisible = false;
videoPlayer.PlaylistVisibility = FeatureVisibility.Disabled;
videoPlayer.MediaEnded += new EventHandler(player_MediaEnded);
LayoutRoot.Children.Add(videoPlayer);
bar_yellow3 = new Image();
bar_yellow3.Source = new BitmapImage(new Uri("/SMF_ProgressiveDownload1;component/assets/bar_y.png", UriKind.Relative));
bar_yellow3.Width = 775;
bar_yellow3.Height = 34;
bar_yellow3.Margin = new Thickness(2948,1034,0,0);
bar_yellow3.Stretch = Stretch.Fill;
bar_yellow3.VerticalAlignment = VerticalAlignment.Top;
bar_yellow3.HorizontalAlignment = HorizontalAlignment.Left;
LayoutRoot.Children.Add(bar_yellow3);
However, when the playing progress is less than 20%, the image blinks randomly. When the SMFPlayer is set to be invisible ( Visibility.Collapsed ) , the image is normal.
I have tried to call the update function of the Image, which is: bar_yellow3.UpdateLayout(); but the method does not solve the blinking issue.
Any solution?

Try use effects (Shazzam will help you) instead using Z order.

Related

Displaying group items in a panel

I have a problem displaying items inside a panel, that is attached to dataflow layout, the panel has label, textbox, button, checkbox and image, when I run the program only the image disaplys even though I have set the postion of each control in the panel, and the panel is looped from the database inside the dataflow layout control, also, when i try to change the size of the panel nothing displays.
I just want someone to point to the right direction , any help is appreciated
thank you
what I have done do far:
foreach ("looped according to the database")
{
Panel pan = new Panel();
PictureBox img = new PictureBox();
Button btn = new Button();
Label house = new Label();
TextBox Street = new TextBox();
CheckBox check = new CheckBox();
pan.Location = new Point();
pan.Size = new System.Drawing.Size();
MemoryStream ms = new MemoryStream();
img .Image = Image.FromStream(ms);
img .Tag = Product.ID;
img .SizeMode = PictureBoxSizeMode.StretchImage;
img .Location = new System.Drawing.Point();
img .Size = new System.Drawing.Size();
img .TabIndex = 0;
house .Text = Product.Name;
house .Location = new System.Drawing.Point();
house .Size = new System.Drawing.Size();
house .AutoSize = true;
house .TabIndex = 1;
Street.Location = new System.Drawing.Point();
Street.Size = new System.Drawing.Size();
Street.TabIndex = 2;
btn.Text = "info";
btn.Size = new System.Drawing.Size();
btn.Location = new System.Drawing.Point();
btn.ForeColor = Color.Green;
btn.TabIndex = 2;
pan.Controls.Add(img);
pan.Controls.Add(check);
pan.Controls.Add(House);
pan .Controls.Add(Street);
pan.Controls.Add(btn);
this.ProductsFlowPanel.Controls.Add(pan);
}
}
I am trying to achieve something similar to this;
image
A couple of things I noticed,
The panel object you created at the start is reassigned on line 10 and 11:
Panel pan = new Panel();
...
pan = new Point(); //probably remove this
pan = new System.Drawing.Size(); //and this
In addition, the size and position of all your controls is just empty points and sizes, eg:
img .Location = new System.Drawing.Point();
img .Size = new System.Drawing.Size();
It should probably be something more like this:
img .Location = new System.Drawing.Point(10,10);
img .Size = new System.Drawing.Size(50,50);
Okay, there are some things in your code which are definitely wrong. I don't know if that's causing the problem, but this is the direction you asked for.
The syntax: something x = new something(); is used to create an object of something
The prerequisite for this is that the something() class should be reachable.
Now let's break this down something x; <-- this declares something as x
x = new something() <-- this initiates x to the something object.
What you're doing in your code is:
Panel pan = new Panel(); //pan is now an object of `Panel()` class.
pan = new Point(); //pan is now an object of `Point()` class.
pan = new System.Drawing.Size(); //pan is now an object of `System.Drawing.Size()` class.
Now, in C#, the last declaration is accepted. So basically, pan isn't an object of the Panel class anymore. Which means your logic for panel won't work.
Another thing I noticed is that the size and position of all your controls is just empty points and sizes.
It should be something like:
img .Location = new System.Drawing.Point(50,50);
img .Size = new System.Drawing.Size(100,100);
Hope this helps :)

BackgroundImage layout to Bottom

I have a task, that can be easily completed with html/css, but I cant figure out how to do it with C# WindowsForms.
I need to create container with dinamic height and with 3 types of BackgroundImage's. To do so I created panel1 and set BackgroundImageLayout of "body.jpg" to tile.
Then I put panel2 and set BackgroundImageLayout of "top.jpg" to none.
So I need to create only one container with "bottom.jpg" but here is the problem.
Image is tall and it must have layout to bottom, but I cant set BackgroundImage of panel3 to Bottom and I cant dock PictureBox to bottom, because in that case it will prevent to set content overlay.
P.S. Sorry if you cant understand some of my explanations - my native language is Russian.
Here is what constuctor created for me:
//
// Charsheet_bg
//
this.Charsheet_bg.AutoSize = true;
this.Charsheet_bg.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("Charsheet_bg.BackgroundImage")));
this.Charsheet_bg.Controls.Add(this.Charsheet_top);
this.Charsheet_bg.Dock = System.Windows.Forms.DockStyle.Left;
this.Charsheet_bg.Location = new System.Drawing.Point(0, 0);
this.Charsheet_bg.Margin = new System.Windows.Forms.Padding(0);
this.Charsheet_bg.MinimumSize = new System.Drawing.Size(285, 0);
this.Charsheet_bg.Name = "Charsheet_bg";
this.Charsheet_bg.Size = new System.Drawing.Size(285, 488);
this.Charsheet_bg.TabIndex = 30;
//
// Charsheet_top
//
this.Charsheet_top.BackColor = System.Drawing.Color.Transparent;
this.Charsheet_top.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("Charsheet_top.BackgroundImage")));
this.Charsheet_top.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.Charsheet_top.Dock = System.Windows.Forms.DockStyle.Fill;
this.Charsheet_top.Location = new System.Drawing.Point(0, 0);
this.Charsheet_top.MinimumSize = new System.Drawing.Size(285, 200);
this.Charsheet_top.Name = "Charsheet_top";
this.Charsheet_top.Size = new System.Drawing.Size(285, 488);
this.Charsheet_top.TabIndex = 31;
And screenshot will be in 5 mins.
Screenshot with tooltips

WPF custom effect animation programmatically

I try to use pixel shader effect animation programmatically in WPF, but below code uses a lot of CPU power.
Is there other method?
â– Call Method
Setting effect while doing sequence.
private void Button_Click(object sender, RoutedEventArgs e)
{
string path = System.IO.Path.GetFullPath(#"WateryEffect.ps");
var uri = new Uri(path);
WpfEffect wpfeffect = new WpfEffect(uri);
BitmapImage img1 = new BitmapImage(new Uri(System.IO.Path.GetFullPath(#"3a28168e68.jpg")));
ImageBrush imgbrush1 = new ImageBrush(img1);
wpfeffect.input1 = imgbrush1;
VisualBrush vbrush = new VisualBrush(text1);
wpfeffect.input1 = vbrush;
BitmapImage img2 = new BitmapImage(new Uri(System.IO.Path.GetFullPath(#"e98f58fa-2e58-4d38-9949-f3f40b6a2b13_7.jpg")));
ImageBrush imgbrush2 = new ImageBrush(img2);
wpfeffect.input2 = imgbrush2;
double i = 1;
do
{
wpfeffect.para0 = i;
image1.Effect = wpfeffect;
image2.Effect = wpfeffect;
image3.Effect = wpfeffect;
image4.Effect = wpfeffect;
DoEvents();
i = i - 0.0001;
} while (i > -1);
}
Doing a loop for this goes against the whole advantage of WPF. You need to run this effect update as a DoubleAnimation. I don't have your .ps file but I'm assuming that para01 is a DependencyProperty.
Try this code:
DoubleAnimation da =
new DoubleAnimation(0.0, 1.0, new Duration(new TimeSpan(0,0,1)); // adjust as needed
(image1.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image2.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image3.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);
(image4.Effect as WpfEffect).BeginAnimation(WpfEffect.para01Property, da);

WinForms transparent picture box not working

I have been trying to lay an image in black/gray over a background, and I would like the background to show through on the transparent sections of the image. The image is definitely saved as a transparent png correctly. What is wrong with the code below?
this.pictureBox14.BackColor = System.Drawing.Color.Transparent;
this.pictureBox14.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox14.BackgroundImage")));
this.pictureBox14.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pictureBox14.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox14.Location = new System.Drawing.Point(486, 337);
this.pictureBox14.Name = "pictureBox14";
this.pictureBox14.Size = new System.Drawing.Size(69, 62);
this.pictureBox14.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox14.TabIndex = 18;
this.pictureBox14.TabStop = false;
this.pictureBox14.Click += new System.EventHandler(this.pictureBox14_Click);

Apply transformation on an image on C# for a Windows Phone application

I'm working on a mini-game where I need to make images go from their initial position to another using a translation transformation.
The problem is: I don't know how to proceed to apply the translation.
So here's the code used to generate my images.
Image myImage1 = new Image();
myImage1.Source = new BitmapImage(new Uri("/Images/image1.png", UriKind.Relative));
myImage1.Name = "image" + index++.ToString();
myImage1.Tap += myImage_Tap;
Canvas.SetLeft(image, 200);
Canvas.SetTop(image, 600);
gameArea.Children.Add(image);
Thanks for your time.
You have two choices to move your image around. The first is using a Canvas like your code shows, but you have to make sure your element is actually within a Canvas. Is your "gameArea" a Canvas? If it's not, your code won't work. The other option is to use Transforms.
var myImage1 = new Image
{
Source = new BitmapImage(new Uri("/Images/image1.png", UriKind.Relative)),
Name = "image" + index++.ToString(),
Tap += myImage_Tap,
RenderTransform = new TranslateTransform
{
X = 200,
Y = 600
}
};
gameArea.Children.Add(image);
Now gameArea can be any type of Panel and it will work.
Note that when using a Canvas, your Top and Left will be from the upper left corner of the Canvas. When using a Transform, your X and Y will be relative to where the element would have originally be drawn.
UPDATE -- Helper class to do simple animations using a Canvas
public sealed class ElementAnimator
{
private readonly UIElement _element;
public ElementAnimator(UIElement element)
{
if (null == element)
{
throw new ArgumentNullException("element", "Element can't be null.");
}
_element = element;
}
public void AnimateToPoint(Point point, int durationInMilliseconds = 300)
{
var duration = new Duration(TimeSpan.FromMilliseconds(durationInMilliseconds));
var easing = new BackEase
{
Amplitude = .3
};
var sb = new Storyboard
{
Duration = duration
};
var animateLeft = new DoubleAnimation
{
From = Canvas.GetLeft(_element),
To = point.X,
Duration = duration,
EasingFunction = easing,
};
var animateTop = new DoubleAnimation
{
From = Canvas.GetTop(_element),
To = point.Y,
Duration = duration,
EasingFunction = easing,
};
Storyboard.SetTargetProperty(animateLeft, "(Canvas.Left)");
Storyboard.SetTarget(animateLeft, _element);
Storyboard.SetTargetProperty(animateTop, "(Canvas.Top)");
Storyboard.SetTarget(animateTop, _element);
sb.Children.Add(animateLeft);
sb.Children.Add(animateTop);
sb.Begin();
}
}
So here's what I did with your code, I took just this part and made it a function:
public void AnimateToPoint(UIElement image, Point point, int durationInMilliseconds = 300)
{
var duration = new Duration(TimeSpan.FromMilliseconds(durationInMilliseconds));
var sb = new Storyboard
{
Duration = duration
};
var animateTop = new DoubleAnimation
{
From = Canvas.GetTop(image),
To = point.Y,
Duration = duration
};
Storyboard.SetTargetProperty(animateTop, new PropertyPath("Canvas.Top")); // You can see that I made some change here because I had an error with what you gave me
Storyboard.SetTarget(animateTop, image);
sb.Children.Add(animateTop);
sb.Begin();
}
And then I made the call with:
Point myPoint = new Point(leftpos, 300); // leftpos is a variable generated randomly
AnimateToPoint(myImage, myPoint);
So now there is still a single error, and it's in the instruction "sb.Begin;".
And it says: Cannot resolve TargetProperty Canvas.Top on specified object.
I reaylly don't know how to proceed.
Thanks for your previous answer!

Categories