locked
Photos in Blend 4 RRS feed

  • Question

  • Hi all!

    Can anyone tell me how to put 3 photos in blend, but each of them should stay only 3 second on the screen, after that to appear the other one?

    Like a little movie?

    Thanks

    Tuesday, February 22, 2011 10:47 AM

Answers

  • In the folder you downloaded navigate to ...\SpriteBehavior\SpriteTestApp\SpriteTestApp\Bin\Release\. In the release folder you can find the SilverLawSpriteBehavior.dll.

    This .dll you add as a reference to your project in Blend.

    • Marked as answer by AlinaFlorina Thursday, February 24, 2011 9:52 AM
    Wednesday, February 23, 2011 1:10 PM

All replies

  • I assume you are asking for a silverlight app. If not, please let me know. If so, you can use this code:

    Mainpage.xaml:

    <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           x:Class="PhotoSwitchLab.MainPage"
           Width="640"
           Height="480">
    
     <Grid x:Name="LayoutRoot"
        Background="White">
      <Button x:Name="bt1"
          Content="Start"
          Height="29"
          Margin="223,0,241,154"
          VerticalAlignment="Bottom" />
      <Image x:Name="imScene"
          Margin="156,62,192,231" />
     </Grid>
    </UserControl>
    

    Mainpage.xaml.vb:

    Imports System.Windows.Threading
    Imports System.Windows.Media.Imaging
    
    Partial Public Class MainPage
     Inherits UserControl
    
     Public Sub New()
      InitializeComponent()
      AddHandler bt1.Click, AddressOf StartSwitching
     End Sub
    
     Private dp As DispatcherTimer
     Private photoCount = 0
    
     Private Sub StartSwitching(ByVal sender As Object, ByVal e As RoutedEventArgs)
    
      dp = New DispatcherTimer With {.Interval = TimeSpan.FromSeconds(1)}
    
      AddHandler dp.Tick, AddressOf SwitchPhoto
    
      photoCount = 1
    
      dp.Start()
    
     End Sub
    
     Private Sub SwitchPhoto(ByVal sender As Object, ByVal e As EventArgs)
    
      If photoCount = 4 Then
    
       photoCount = 0
    
       dp.Stop()
    
       RemoveHandler dp.Tick, AddressOf SwitchPhoto
    
      Else
    
       ChangeImage(photoCount)
    
       photoCount += 1
    
      End If
    
     End Sub
    
     Private Sub ChangeImage(ByVal ID As Integer)
    
      imScene.Source = New BitmapImage With {.UriSource = New Uri(GetImageName(ID), UriKind.RelativeOrAbsolute)}
    
     End Sub
    
     Private Function GetImageName(ByVal index As Integer) As String
    
      Return String.Format("photos/T" + index.ToString + ".png", index)
    
     End Function
    
    
    End Class
    

    What you need are three .png files in a folder named "photos", the files are named "T1", "T2" and "T3".

    Hope this helps.

    Tuesday, February 22, 2011 11:47 AM
  • Yes.

    I'm working on a project in Silverlight but i use Expression Blend 4 .

    But this class "Mainpage.xaml.vb" were i shoul create.Or how?

    I'm really new in silverlight an expression blend.

    Thanks

    Tuesday, February 22, 2011 1:22 PM
  • Do you have Visual Studio 201 too?

    A) If you have Visual Studio 2010:

    1) Right click your project name in the blend project explorer and click "Edit in Visual Studio".

    2) A new instance of Visual Studio 2010 opens. There you can edit Mainpage.xaml.vb and add the code I provided in my previous reply.

    One thing to note: When you created your silverlight rpohect using Blend you chose a code behind language. This was either C# or VB. So to use my code example you should have created your silverlight project with VB as code behind programming language.

    One word regarding the background of xaml and code behind files: Any xaml page you create for your project has got a xaml file and a corresponding xaml.vb or xaml.cs file, whereas the corresponding xaml.xy file depends on which code behind programming language you chose when you created your project initially (either VB or C#). The purpose of a code behind file is (among others) to provide access to the objects you created in the xaml file. MainPage.xaml has got e.g. an element defined in xaml named "LayoutRoot". Each element which has got an x:Name attribute set can be accessed from code behind. Technically this can be well understood by a simple rule. Each xaml page is from a developers perspective a seperate class, whereas each xaml page has got to parts: The one part is the xaml file and the other part is the code behind file, which is either of type xaml.vb or of type xaml.cs. So the .xaml file and the .xaml.vb/.xaml.cs file are both so called partial classes which together build the one class. So I guess you get a good base understanding of how xaml and the code behind file are working together when you remember that both, xaml and xaml.vb, are partial classes which define one class, which is in case of MainPage.xaml the class called MainPage.

    B) If you don't have Visual Studio 2010:

    1) Open the tree view of MainPage.xaml in the project explorer of Blend using the little triangle left to the file name. The code behindfile MainPage.xaml.vb or MainOage.xaml.cs appears.

    2) Double click the code behind file and add the code provided in my previous reply.

    I guess you are more a designer than a developer. So if you have any trouble in using the code I provided please post again.

    There might be an alternative solution for you with which you doesn't have to write any code. If have written a behavior called SpriteAnimationBehavior you might want to check out. Follow the instruction I provided in using this behavior. Set the FramesPerSecond property to 1 and the TotalImageCount property to 3. Please note one limitation currently: In the current version of the behavior the animation starts only when the user clicks on the image.

     

    Tuesday, February 22, 2011 2:23 PM
  • where i found SpriteAnimationBehavior?
    Wednesday, February 23, 2011 1:02 PM
  • In the folder you downloaded navigate to ...\SpriteBehavior\SpriteTestApp\SpriteTestApp\Bin\Release\. In the release folder you can find the SilverLawSpriteBehavior.dll.

    This .dll you add as a reference to your project in Blend.

    • Marked as answer by AlinaFlorina Thursday, February 24, 2011 9:52 AM
    Wednesday, February 23, 2011 1:10 PM
  • I saw you really good at Expression Blend.So i think go are going to help me again because i have another problem.

    I want to create  a web application which contain a photo editor.But the photo editor is in C#.I don;t have any idea how to put the C# project

    (the photo editor) in the site(which i will create in Expression Blend 4).Can you please help me?

    I don't want to start from the beginning with photo editor because this one i had already created last year.

    Now my teacher told me to make this application to be an online application.Not only a desktop one.

    Thanks a lot!

    Thursday, February 24, 2011 10:01 AM
  • Of course I would like to help you. But here at the Expression Blend forum and of course at the official Silverlight forums you have great communities which can are surely willing to help you. So I would suggest that you open a new thread in the forum and ask a new and specific question in order to benefit from the power of the communities.

    A first step to turn a desktop app into a silverlight app would be to provide the source code of the desktop app.

    Thursday, February 24, 2011 11:59 AM
  • A part from The source code from the main class is bellow.

    My photo editor i've made from a lot of form

     

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Text;
    using System.Windows.Forms;

    namespace IP_Project
    {
        public partial class MainF : Form
        {
            double curentzoom = 1.0;
            public string imagename = null;
            public int imagetype = 1;
            public MainF()
            {
                InitializeComponent();
            }


            private void openImageToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    imagename = openFileDialog1.FileName;
                    String ext = imagename.ToUpper();
                    if (ext.EndsWith("BMP"))
                        imagetype = 1;
                    else if (ext.EndsWith("JPG") || ext.EndsWith("JPEG"))
                        imagetype = 2;
                    else if (ext.EndsWith("GIF"))
                        imagetype = 3;
                    else if (ext.EndsWith("PNG"))
                        imagetype = 4;
                    else if (ext.EndsWith("WMF"))
                        imagetype = 5;

                    autofitToolStripMenuItem.Checked = false;
                    normalSizeToolStripMenuItem.Checked = true;
                    stretchToolStripMenuItem.Checked = false;
                    pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
                    pictureBox1.Dock = DockStyle.None;
                    curentzoom = 1.0;
                    status();
                    //imagetype = openFileDialog1.FilterIndex;
                    Bitmap bmp = new Bitmap(imagename);
                    pictureBox1.Image = bmp;
                }

            }

            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Close();
            }

            private void reloadImageToolStripMenuItem_Click(object sender, EventArgs e)
            {
               if (pictureBox1.Image != null)
                {
                    Bitmap bmp = new Bitmap(imagename);
                    pictureBox1.Image = bmp;
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void negativeToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {      
                    Bitmap bmp2 = new Bitmap(pictureBox1.Image);
                    BitmapData data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                    unsafe
                    {
                        byte* ptr = (byte*)(data.Scan0);
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {
                                ptr[0] = (byte)(255 - ptr[0]);
                                ptr[1] = (byte)(255 - ptr[1]);
                                ptr[2] = (byte)(255 - ptr[2]);
                                ptr = ptr + 3;
                            }
                            ptr += data.Stride - data.Width * 3;
                        }
                    }
                    bmp2.UnlockBits(data);
                    pictureBox1.Image = bmp2;
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void equalizeToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Bitmap bmp2 = new Bitmap(pictureBox1.Image);
                    BitmapData data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                    unsafe
                    {
                        byte* ptr = (byte*)(data.Scan0);
                        byte min0 = 255;
                        byte min1 = 255;
                        byte min2 = 255;

                        byte max0 = 0;
                        byte max1 = 0;
                        byte max2 = 0;
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {
                                if (ptr[0] < min0)
                                {
                                    min0 = ptr[0];
                                }

                                if (ptr[1] < min1)
                                {
                                    min1 = ptr[1];
                                }

                                if (ptr[2] < min2)
                                {
                                    min2 = ptr[2];
                                }




                                if (ptr[0] > max0)
                                {
                                    max0 = ptr[0];
                                }

                                if (ptr[1] > max1)
                                {
                                    max1 = ptr[1];
                                }

                                if (ptr[2] > max2)
                                {
                                    max2 = ptr[2];
                                }

                                ptr = ptr + 3;
                            }
                            ptr += data.Stride - data.Width * 3;
                        }

                        ptr = (byte*)(data.Scan0);
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {

                                if (max0 > min0) ptr[0] = (byte)(((ptr[0] - min0) * 255) / (max0 - min0));
                                else ptr[0] = 0;
                                if (max1 > min1) ptr[1] = (byte)(((ptr[1] - min1) * 255) / (max1 - min1));
                                else ptr[1] = 0;
                                if (max2 > min2) ptr[2] = (byte)(((ptr[2] - min2) * 255) / (max2 - min2));
                                else ptr[2] = 0;
                                ptr = ptr + 3;
                            }
                            ptr += data.Stride - data.Width * 3;
                        }
                    }
                    bmp2.UnlockBits(data);
                    pictureBox1.Image = bmp2;
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void brightenessToolStripMenuItem_Click(object sender, EventArgs e)
            {
               if (pictureBox1.Image != null)
                {    
                    Program.brigh.Activate();
                    Program.brigh.Show();
                    Program.brigh.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");         
            }


            private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        imagetype = saveFileDialog1.FilterIndex;
                        Bitmap temp = new Bitmap(pictureBox1.Image);
                        pictureBox1.Image.Dispose();
                        pictureBox1.Image = null;
                        if (saveFileDialog1.FilterIndex == 1)
                            temp.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
                        else if (saveFileDialog1.FilterIndex == 2)
                            temp.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
                        else if (saveFileDialog1.FilterIndex == 3)
                            temp.Save(saveFileDialog1.FileName, ImageFormat.Gif);
                        else if (saveFileDialog1.FilterIndex == 4)
                            temp.Save(saveFileDialog1.FileName, ImageFormat.Png);
                        else if (saveFileDialog1.FilterIndex == 5)
                            temp.Save(saveFileDialog1.FileName, ImageFormat.Wmf);
                        imagename = saveFileDialog1.FileName;
                        pictureBox1.Image = temp;
                        status();
                    }
                }
                else
                {
                    MessageBox.Show(this,"No Image Loaded!","Error");
                }
            }

            private void closeToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //pictureBox1.Image.Dispose();
                pictureBox1.Image = null;
                normalSizeToolStripMenuItem.Checked = true;
                pictureBox1.Dock = DockStyle.None;
                curentzoom = 1.0;
                status();
            }

            private void saveToolStripMenuItem_Click(object sender, EventArgs e)
            {
                try
                {

                    if (pictureBox1.Image != null)
                    {
                        Bitmap temp = new Bitmap(pictureBox1.Image);
                        pictureBox1.Image.Dispose();                   
                        pictureBox1.Image = null;
                        if (imagetype == 1)
                            temp.Save(imagename, ImageFormat.Bmp);
                        else if (imagetype == 2)
                            temp.Save(imagename, ImageFormat.Jpeg);
                        else if (imagetype == 3)
                            temp.Save(imagename, ImageFormat.Gif);
                        else if (imagetype == 4)
                            temp.Save(imagename, ImageFormat.Png);
                        else if (imagetype == 5)
                            temp.Save(imagename, ImageFormat.Wmf);
                        temp = new Bitmap(imagename);
                        pictureBox1.Image = temp;
                        status();
                    }
                    else
                    {
                        MessageBox.Show(this, "No Image Loaded!", "Exception");
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(this, err.Message, "Error!");
                };
            }

            private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Program.abfrm.Activate();
                Program.abfrm.Show();
            }

            private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.propfrm.Activate();
                    Program.propfrm.Show();
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void flipToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.flp.Activate();
                    Program.flp.Show();
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void contrastToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.contr.Activate();
                    Program.contr.Show();
                    Program.contr.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void grayscaleToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Bitmap bmp2 = new Bitmap(pictureBox1.Image);
                    BitmapData data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                    unsafe
                    {
                        byte* ptr = (byte*)(data.Scan0);
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {
                                byte med = 0;
                                med = (byte)((ptr[0] + ptr[1] + ptr[2]) / 3);
                                ptr[0] = med;
                                ptr[1] = med;
                                ptr[2] = med;
                                ptr = ptr + 3;
                            }
                            ptr += data.Stride - data.Width * 3;
                        }
                    }
                    bmp2.UnlockBits(data);
                    pictureBox1.Image = bmp2;
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }


            private void autofitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (autofitToolStripMenuItem.Checked == false)
                {
                    autofitToolStripMenuItem.Checked = true;               
                    normalSizeToolStripMenuItem.Checked = false;
                    stretchToolStripMenuItem.Checked = false;
                    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                    pictureBox1.Dock = DockStyle.Fill;
                    curentzoom = 1.0;
                    status();

                }
            }

            private void normalSizeToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (normalSizeToolStripMenuItem.Checked == false)
                {
                    autofitToolStripMenuItem.Checked = false;
                    normalSizeToolStripMenuItem.Checked = true;
                    stretchToolStripMenuItem.Checked = false;
                    pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
                    pictureBox1.Dock = DockStyle.None;
                    curentzoom = 1.0;
                    status();

                }
            }

            private void stretchToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (stretchToolStripMenuItem.Checked == false)
                {
                    autofitToolStripMenuItem.Checked = false;
                    normalSizeToolStripMenuItem.Checked = false;
                    stretchToolStripMenuItem.Checked = true;
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Dock = DockStyle.Fill;
                    curentzoom = 1.0;
                    status();
                }
            }
            public void status(){
                zoomlevel.Text = "Zoom: "+curentzoom.ToString()+"x";
                imageN.Text = "Image: " + imagename;
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                if (pictureBox1.SizeMode == PictureBoxSizeMode.Zoom)
                {
                    autofitToolStripMenuItem.Checked = true;
                    normalSizeToolStripMenuItem.Checked = false;
                    stretchToolStripMenuItem.Checked = false;
                    pictureBox1.Dock = DockStyle.Fill;
                    curentzoom = 1.0;
                }
                else if (pictureBox1.SizeMode == PictureBoxSizeMode.AutoSize)
                {
                    autofitToolStripMenuItem.Checked = false;
                    normalSizeToolStripMenuItem.Checked = true;
                    stretchToolStripMenuItem.Checked = false;
                    pictureBox1.Dock = DockStyle.None;
                    curentzoom = 1.0;
                }
                else if (pictureBox1.SizeMode == PictureBoxSizeMode.StretchImage)
                {
                    autofitToolStripMenuItem.Checked = false;
                    normalSizeToolStripMenuItem.Checked = false;
                    stretchToolStripMenuItem.Checked = true;
                    pictureBox1.Dock = DockStyle.Fill;
                    curentzoom = 1.0;
                }
                status();
                Program.binar.TopMost = true;
                Program.brigh.TopMost = true;
                Program.contr.TopMost = true;
                Program.flp.TopMost = true;
                Program.hist.TopMost = true;
                Program.minmax.TopMost = true;
                Program.propfrm.TopMost = true;
                Program.conv.TopMost = true;
                Program.abfrm.TopMost = true;
                Program.help.TopMost = true;

            }

            private void zoomToolStripMenuItem_Click(object sender, EventArgs e)
            {
                //TODO
            }

            private void binarizeToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.binar.Activate();
                    Program.binar.Show();
                    Program.binar.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void histogramToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.hist.Activate();
                    Program.hist.Show();
                    Program.hist.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void minToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.minmax.Activate();
                    Program.minmax.Show();
                    Program.minmax.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

            private void opaqueToolWindowsToolStripMenuItem_Click(object sender, EventArgs e)
            {
                double val=0.8;
                if (opaqueToolWindowsToolStripMenuItem.Checked == false)
                {
                    opaqueToolWindowsToolStripMenuItem.Checked = true;
                    Program.binar.Opacity = val;
                    Program.brigh.Opacity = val;
                    Program.contr.Opacity = val;
                    Program.flp.Opacity = val;
                    Program.hist.Opacity = val;
                    Program.minmax.Opacity = val;
                    Program.propfrm.Opacity = val;
                    Program.conv.Opacity = val;
                    Program.abfrm.Opacity = val;
                    Program.help.Opacity = val;
                }
                else
                {
                    opaqueToolWindowsToolStripMenuItem.Checked = false;
                    Program.binar.Opacity = 1;
                    Program.brigh.Opacity = 1;
                    Program.contr.Opacity = 1;
                    Program.flp.Opacity = 1;
                    Program.hist.Opacity = 1;
                    Program.minmax.Opacity = 1;
                    Program.propfrm.Opacity = 1;
                    Program.conv.Opacity = 1;
                    Program.abfrm.Opacity = 1;
                    Program.help.Opacity = 1;
                }
            }

            private void toolWindowsAlwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (toolWindowsAlwaysOnTopToolStripMenuItem.Checked == false)
                {
                    toolWindowsAlwaysOnTopToolStripMenuItem.Checked = true;
                    Program.binar.TopMost = true;
                    Program.brigh.TopMost = true;
                    Program.contr.TopMost = true;
                    Program.flp.TopMost = true;
                    Program.hist.TopMost = true;
                    Program.minmax.TopMost = true;
                    Program.propfrm.TopMost = true;
                    Program.conv.TopMost = true;
                    Program.abfrm.TopMost = true;
                    Program.help.TopMost = true;
                }
                else
                {
                    toolWindowsAlwaysOnTopToolStripMenuItem.Checked = false;
                    Program.binar.TopMost = false;
                    Program.brigh.TopMost = false;
                    Program.contr.TopMost = false;
                    Program.flp.TopMost = false;
                    Program.hist.TopMost = false;
                    Program.minmax.TopMost = false;
                    Program.propfrm.TopMost = false;
                    Program.conv.TopMost = false;
                    Program.abfrm.TopMost = false;
                    Program.help.TopMost = false;
                }
            }

            private void convolutionToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (pictureBox1.Image != null)
                {
                    Program.conv.Activate();
                    Program.conv.Show();
                    Program.conv.last = new Bitmap(pictureBox1.Image);
                }
                else MessageBox.Show(this, "No Image Loaded!", "Error");
            }

          

          
        }
        }


    Thursday, February 24, 2011 12:55 PM