I have to do a slide show off images stored in my isolated storage.. but i am beginner in windows phone and i have some dificulties.. i already know how to present the images, or show the images in the screen.. but i want to present the images 2 seconds each one.. theres some funcionalty to define the time to reproduce? Any example?
IsolatedStorageFileStream stream = new IsolatedStorageFileStream(name_image, FileMode.Open, myIsolatedStorage);
var image = new BitmapImage();
image.SetSource(stream);
image1.Source = image;
This is how i open the image. I have a foreach with 5 name of images then i open each one.. but i want to see the images 2 seconds..
You could make the current thread sleep for 2 seconds:
System.Threading.Thread.Sleep(2000);
As the last sentence in the foreach body. It is not very neat, but it will do the job.
A better way is to use Reactive Extension.
First take a look at my answer in this post. It tells you what dlls you will need as well as some useful links.
Basically you need to store you images in a collection and then use Rx (GenerateWithTime) to create a observable sequence with time dimension based on the collection. Finally you call a method to add one image and subscribe it to the observable sequence.
Here is one working example,
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// create a collection to store your 5 images
var images = new List<Image>
{
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 }
};
// create a time dimension (2 seconds) to the generated sequence
IObservable<Image> getImages = Observable.GenerateWithTime(0, i => i <= images.Count - 1, i => images[i], _ => TimeSpan.FromSeconds(2), i => ++i);
// subscribe the DisplayOneImage handler to the sequence
getImages.ObserveOnDispatcher().Subscribe(DisplayOneImage);
}
private void DisplayOneImage(Image image)
{
// MyItems is an ItemsControl on the UI
this.MyItems.Items.Add(image);
}
Hope this helps. :)
Related
I'm using Xamarin.Forms with Urhosharp in my project. I'm tring to set a matrial from an image on a sphere, everything is OK in my Android project but in iOS project, when I set material from some jpg files it doesn't work and all I get is a black screen.
Here is the jpg that works correctly:
And here is the other one that doesn't:
This is my code:
var scene = new Scene();
scene.CreateComponent<Octree>();
// Node (Rotation and Position)
var node = scene.CreateChild("room");
node.Position = new Vector3(0, 0, 0);
//node.Rotation = new Quaternion(10, 60, 10);
node.SetScale(1f);
// Model
var modelObject = node.CreateComponent<StaticModel>();
modelObject.Model = ResourceCache.GetModel("CustomModels/SmoothSphere.mdl");
var zoneNode = scene.CreateChild("Zone");
var zone = zoneNode.CreateComponent<Zone>();
zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
zone.AmbientColor = new Color(1f, 1f, 1f);
//get image from byte[]
//var url = "http://www.wsj.com/public/resources/media/0524yosemite_1300R.jpg";
//var wc = new WebClient() { Encoding = Encoding.UTF8 };
//var mb = new MemoryBuffer(wc.DownloadData(new Uri(url)));
var mb = new MemoryBuffer(PanoramaBuffer.PanoramaByteArray);
var image = new Image(Context) { Name = "MyImage" };
image.Load(mb);
//or from resource
//var image = ResourceCache.GetImage("Textures/grave.jpg");
var isFliped = image.FlipHorizontal();
if (!isFliped)
{
throw new Exception("Unsuccessful flip");
}
var m = Material.FromImage("1.jpg");
m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
m.CullMode = CullMode.Cw;
//m.SetUVTransform(Vector2.Zero, 0, 0);
modelObject.SetMaterial(m);
// Camera
var cameraNode = scene.CreateChild("camera");
_camera = cameraNode.CreateComponent<Camera>();
_camera.Fov = 75.8f;
_initialZoom = _camera.Zoom;
// Viewport
Renderer.SetViewport(0, new Viewport(scene, _camera, null));
I already tried to change compression level, ICCC profile and ...
I asked the same question in forums.xamarin.com and someone answered the question and I'll share it here :
In iOS every texture needs to have a power of two resolution, like 256 x 256 or 1024 x 512. Check if that is the issue. Additionally check that your using the latest UrhoSharp version.
Also make sure that the image is set as BundleResource in the iOS project.
I want to code a splash screen which, after clicking in a presentation´s image start to do an animation (over the image) and, 5 seconds after, go to a Login page.
I tried to find the solution of it, but the answer use to be related with a specific plataform.
My idea is to code it over cross plataform.
After researching, I found the solution coming from Xamarin offical page (animation´s samples) and another page (for the delay) I don´t remember the site...
I´m posting this question and answer because I think could be really interesting for the community.
Button startButton = new Button() { Image = "splashlogo.png", BackgroundColor = Xamarin.Forms.Color.Transparent, HorizontalOptions = Xamarin.Forms.LayoutOptions.Center, Scale = 3.5};
startButton.Clicked += async (object sender, EventArgs e) =>
{
var parentAnimation = new Animation();
var scaleUpAnimation = new Animation(v => startButton.Scale = v, 1, 2, Easing.SpringIn);
var rotateAnimation = new Animation(v => startButton.Rotation = v, 0, 360);
var scaleDownAnimation = new Animation(v => startButton.Scale = v, 2, 1, Easing.SpringOut);
parentAnimation.Add(0, 0.5, scaleUpAnimation);
parentAnimation.Add(0, 1, rotateAnimation);
parentAnimation.Add(0.5, 1, scaleDownAnimation);
parentAnimation.Commit(startButton, "ChildAnimations", 16, 4000, null);
await Task.Delay(5000);
await App.Current.MainPage.Navigation.PushModalAsync(new Login());
};
public static async Task Sleep(int ms)
{
await Task.Delay(ms);
}
I have created this code
Uri _blendImageUri = new Uri(#"Assets/1.png", UriKind.Relative);
var _blendImageProvider = new StreamImageSource((System.Windows.Application.GetResourceStream(_blendImageUri).Stream));
var bf = new BlendFilter(_blendImageProvider);
Filter work nice. But I want change image size for ForegroundSource property. How can I load image with my size?
If I understood you correctly you are trying to blend ForegroundSource with only a part of the original image? That is called local blending at it is currently not supported on the BlendFilter itself.
You can however use ReframingFilter to reframe the ForegroundSource and then blend it. Your chain will look like something like this:
using (var mainImage = new StreamImageSource(...))
using (var filterEffect = new FilterEffect(mainImage))
{
using (var secondaryImage = new StreamImageSource(...))
using (var secondaryFilterEffect = new FilterEffect(secondaryImage))
using (var reframing = new ReframingFilter(new Rect(0, 0, 500, 500), 0)) //reframe your image, thus "setting" the location and size of the content when blending
{
secondaryFilterEffect.Filters = new [] { reframing };
using (var blendFilter = new BlendFilter(secondaryFilterEffect)
using (var renderer = new JpegRenderer(filterEffect))
{
filterEffect.Filters = new [] { blendFilter };
await renderer.RenderAsync();
}
}
}
As you can see, you can use the reframing filter to position the content of your ForegroundSource so that it will only blend locally. Note that when reframeing you can set the borders outside of the image location (for example new Rect(-100, -100, 500, 500)) and the areas outside of the image will appear as black transparent areas - exactly what you need in BlendFilter.
I've been doing a essay about map on windows phone. I added pushpins default into map and its content is a image. I want to show information when I tap or click on pushpin, but I don't know what to do. I've just thought about use tooltip to show info, but I can't do it.
here is my createpushpin function.
can you help me? thank you for all kind of you!
private void CreateNewPushpin(object selectedItem)
{
var pushpinPrototype = selectedItem as Pushpinsmodel;
var pushpinicon = pushpinPrototype.Icon;
Pushpin pushpins = new Pushpin() { Tag = adress.Name };
pushpins.Background = new SolidColorBrush(Colors.Green);
pushpins.Location = new GeoCoordinate(lad, long);
ImageBrush image = new ImageBrush() {
ImageSource = new System.Windows.Media.Imaging.BitmapImage
(pushpinicon)};
Ellipse elip = new Ellipse()
{
Fill = image,
Name = adress.Name,
StrokeThickness = 10,
Height = 30,
Width = 30
};
pushpins.Content = elip;
var tooltipText = new ToolTip { Content = adress.Name};
ToolTipService.SetToolTip(pushpins, tooltipText);
map1.Children.Add(pushpins);
listpushpin.Add(pushpins);
this.map1.SetView(pushpins.Location, 18.0);
}
hi i am trying to show image of my file in previwew pane i am able to display the image of my file but i am stuck in the part where i need write some text on the image before adding it to preview pane.
// create an image object, using the filename we just retrieved
String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
//file.CreationTime.ToString();
//------------------------------------
//Load the Image to be written on.
Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
//Save the new image to the response output stream.
bitMapImage.Save(strImageFile, ImageFormat.Png);
//------------------------------------
// Create a picture box control
PictureBox p = new PictureBox();
p.Dock = DockStyle.Fill;
p.Image = bitMapImage;
//p.Image = System.Drawing.Image.FromFile(strImageFile);
p.SizeMode = PictureBoxSizeMode.Zoom;
Controls.Add(p);
//graphicImage.Dispose();
//bitMapImage.Dispose();
Only the image appease and not the text, any idea what i might be missing.
thanks
Narrow it down too:
PictureBox p = new PictureBox();
// create an image object, using the filename we just retrieved
String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
Graphics graphicImage = Graphics.FromImage(bitMapImage);
graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
graphicImage.DrawImage(bitMapImage, new Rectangle(205, 0, 200, 200), 0, 0, bitMapImage.Width, bitMapImage.Height, GraphicsUnit.Pixel);
p.Image = bitMapImage;
p.Dock = DockStyle.Fill;
Controls.Add(p);
But i am getting an exception on