WPF - Display combination of contents(images, video, text) - wpf

I’m trying to display contents. Contents can be a combination of image, video & text. Each one of them has a start date time & end date time.
I could display one image using tag but I couldn’t display series of images in a loop. Its displaying only last image or video. Immediate help appreciated.
Code snippet as follows -
// Check if Content if its an Image
if (dataTable.Rows[nCnt][1].Equals("I"))
{
imageSource = new BitmapImage(new Uri(strContent));
Image1.Visibility = Visibility.Visible;
Image1.Source = imageSource;
}
else
// Check if Content if its an Video
if (dataTable.Rows[nCnt][1].Equals("V"))
{
MyVideo1.Source = new Uri(strContent);
MyVideo1.Visibility = Visibility.Visible;
MyVideo1.Play();
}

You are filling the same image and video container(Image1, MyVideo1), with diferent images and videos. So the last one is the only one displayed. You should create a collection of images and videos. List<YourMediaType> or ObservableCollection<YourMediaType> if you are using MVVM.

Related

How to create image box in xamarin by code?

I want to fetch a set of images from the database and display them in the application. The number of images varies according to each user of the application. The user is the one who adds the images to the database and they are displayed to him in the form (Horizontal layout)
in c# windows app i can use this code to create picture box then add it to flowLayoutPanel
and when click on image, do something
var pic = new PictureBox
{
Name = "Pic" + txt.id.ToString(),
Size = new Size(118, 114),
Image = Image.FromStream(byteStream),
SizeMode = PictureBoxSizeMode.Zoom,
BorderStyle = BorderStyle.FixedSingle,
Cursor = Cursors.Hand,
};
pic.Click += Pic_Click;
flowLayoutPanel.Controls.Add(pic);
how can i do the same in xamarin

Make videos scrollable

I have a scrollabillity issue in a Form, layered out by BoxLayout.y().
The form contains many Tabs (with fixed size), each tab of the Tabs can contain an image or a video (the video is inside a BorderLayout to scale it at the tab size).
If an image is shown, the scrolling up and down works correctly.
If a video is shown, the y scrolling is not possibile, I can only swipe to change the tab.
I suppose that the cause of this issue is that videos are native component (I used the Codename One API to show the videos).
How can I solve or workaround this issue? This is crucial for the app design. Thanks for the tips.
The video.setEnabled(false) workaround (Make videos scrollable) doesn't work.
I workaround in a different way, inserting the MediaPlayer container in a LayeredLayout container, and then placing a Button over the MediaPlayer. A generic empty Label doesn't work, but an empty Button works. Of course I have to override calcPreferredSize to make the MediaPlayer and the Button of the same size (or use a different approach to make them of the same size).
This allows scrolling, but prevents the tapping of the play and pause Buttons (that are over the video). I solved also this issue.
In short, this is my solution, tested on Simulator, Android and iOS (in the following code, note that videoBtnsCnt is a Container over the video, in which I inserted play and pause Buttons):
MediaPlayer mediaPlayer = new MediaPlayer(video) {
#Override
public Dimension getPreferredSize() {
return new Dimension(size, size);
}
};
Container mediaPlayerCnt = new Container(new LayeredLayout(), "NoMarginNoPadding") {
#Override
public Dimension getPreferredSize() {
return new Dimension(size, size);
}
};
mediaPlayerCnt.add(mediaPlayer);
Button allowScrollingLabel = new Button() {
#Override
public Dimension getPreferredSize() {
return new Dimension(size, size);
}
};
allowScrollingLabel.setUIID("NoMarginNoPadding");
allowScrollingLabel.addActionListener(l -> {
Component responder = videoBtnsCnt.getResponderAt(l.getX(), l.getY());
if (responder instanceof Button) {
// it can be a play button or a pause button
((Button) responder).pressed();
((Button) responder).released();
}
});
mediaPlayerCnt.add(allowScrollingLabel);

Gif Animation is not working as expected in WPF

I am having one multi thread WPF application. In that application am using gif image with one of the threads. I need to check whether database connection is established or not ,until then the icon should be loading gif, after that which will turn into success or failure icon accordingly.
I have used the following code to set the gif initially .
<Image x:Name="sample" Grid.Row="1" gif:ImageBehavior.AnimatedSource="{Binding DataBaseImageSource}" Margin="{Binding ElementName=BorderContainer, Path=Margin}" />
After that i am changing the icon using below code. This code will get executed after window.show() method.
try
{
myContext.Database.Connection.Open();
myContext.Database.Connection.Close();
this.DataBaseImageSource = (BitmapImage)Application.Current.FindResource("SuccessIcon");
}
catch (SqlException e)
{
this.ResultSummary = "Failure";
this.DataBaseSummary = e.Message.ToString();
this.DataBaseImageSource = (BitmapImage)Application.Current.FindResource("ErrorIcon");
return false;
}
return true;
once i called this above window.show() method, then am changing the animated source based on the database availability .
But the gif is not at all loading it behaves like a normal png image, after that the image gets changed based on the result. how can i make gif to be animated followed by source change?

Tiny image size when adding an image to a button from an imagelist in c#

I am trying to show an image within a button using an ImageList, however when I run the code the image is being shown as a tiny 10x10 image. The actual size of the image is 193x261
Here is how I add the image to the list
ImageList imageList = new ImageList();
try
{
imageList.Images.Add(Image.FromFile(Directory.GetCurrentDirectory() + #"\Images\Phone.png"));
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
and here is how I add the image to the button
call.BackgroundImage = imageList.Images[0];
call.BackgroundImageLayout = ImageLayout.Center;
I forgot to mention, the button is called 'call', the size of the button is 120x110.
Try this:
imageList.ImageSize = new Size(call.Width, call.Height);
It sets the image list size to that of the button (its parent container).

how to display the latest captured video thumbnail beside my capture button in camera app ios

I am building a camera based app. In this app I am able to display the latest captured image thumbnail beside the capture button. Now how to do the same with the video thumbnail, I mean how to display the latest captured video thumbnail beside my capture button in camera ios. Thanks in advance.
Assuming that you are enumerating the assets using an enumeration block -
For the assets that you are enumerating, check the property key ALAssetPropertyType in your enumeration block like this:
if([asset valueForProperty: ALAssetPropertyType] == ALAssetTypeVideo){
CGImageRef thumbnailVidoeImageRef = [asset thumbnail];
// Do what you want with this CGImageRef. Convert to UIImage etc.
}

Resources