How to display images one after another on a single page - wpf

This is my code , please let me know the solution for it.
var images = (from pd in SvarkWindow.prodlist where pd.Product_name.StartsWith(imgname) select pd.Image).ToList();
BitmapImage b = new BitmapImage();
b.BeginInit();
//b.UriSource = new Uri(images.ElementAtOrDefault(0), UriKind.Relative);
b.UriSource = new Uri("http://portal.liftech.in/presc/" + images.ElementAtOrDefault(0));
b.EndInit();
// ... Get Image reference from sender.
Image img1 = Productimage0 as Image;
img1.Source = b;

I did this in this way.
look at the code.
ImageSource imageSource = new BitmapImage(new Uri("http://portal.liftech.in/presc/" + images.ElementAtOrDefault(0)));
System.Windows.Controls.Image image1 = new System.Windows.Controls.Image();
image1.Source = imageSource;
Grid.SetColumn(image1, 0);//image1 is added to column 0
Grid.SetRow(image1, 0);//row 0
ProductGrid0.Children.Add(image1);

Related

WPF, bad texture seams on an obj model

I'm loading and texturing a model like that
Model3DGroup modelGroupScull = importer.Load("C:\\Users\\х\\Desktop\\a.obj");
modelScull = (GeometryModel3D)modelGroupScull.Children[0];
BitmapImage bitImageScull = new BitmapImage();
bitImageScull.BeginInit();
bitImageScull.UriSource = new Uri("C:\\Users\\х\\Desktop\\sc.jpg");
bitImageScull.EndInit();
ImageBrush imageBrushScull = new ImageBrush();
imageBrushScull.ViewportUnits = BrushMappingMode.Absolute;
imageBrushScull.ImageSource = bitImageScull;
diffuseMatScull = new DiffuseMaterial();
diffuseMatScull.Brush = imageBrushScull;
modelScull.Material = diffuseMatScull;
Model3DGroup2.Children.Add(modelScull);
Yet the seams look strange (they looks good in 3dMax), as well as the texture inside of the object is blue. Is there a way to fix it and made the object textured inside as well?
Thanks! )

byte[] to ImageSource stream

I need to convert byte[] to BitmapImage and show it in WPF image control. (img.Source = ...).
if i convert it like this:
m_photo = new BitmapImage();
using (MemoryStream stream = new MemoryStream(photo.ToArray()))
{
m_photo.BeginInit();
m_photo.StreamSource = stream;
m_photo.EndInit();
}
it can't do XAML binding to Source property because "m_photo owns another stream"... What can I do?
Set the cache option to OnLoad after begininit
m_photo.CacheOption = BitmapCacheOption.OnLoad;
EDIT: complete code for bmp array to Image source
DrawingGroup dGroup = new DrawingGroup();
using (DrawingContext drawingContext = dGroup.Open())
{
var bmpImage = new BitmapImage();
bmpImage.BeginInit();
bmpImage.CacheOption = BitmapCacheOption.OnLoad;
bmpImage.StreamSource = new MemoryStream(photoArray);
bmpImage.EndInit();
drawingContext.DrawImage(bmpImage, new Rect(0, 0, bmpImage.PixelWidth, bmpImage.PixelHeight));
drawingContext.Close();
}
DrawingImage dImage = new DrawingImage(dGroup);
if (dImage.CanFreeze)
dImage.Freeze();
imageControl.Source = dImage;
Ok, I just found solution. If use this code (converting byte[] to bitmapSource) in code of class - you have this error, that the object is in another stream. But if create a Converter (IValueConverter) and use it with same code of converting in XAML binding - everything ok!
Thanks everybody!

dynamically added control not rendering, silverlight

Hello i have a canvas with the name Layout. I want to add some childs to it in code behind. Here is the code.
private void AddItem(int TruePosition, int CurrentPosition, string ImageFileName)
{
Image img = new Image();
img.Source = new BitmapImage(new Uri(#"/Images/" + ImageFileName, UriKind.Relative));
img.Width = 100.0;
img.Height = 400.0;
img.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
img.Stretch = Stretch.None;
Border b = new Border();
b.SetValue(Canvas.TopProperty, 200.0);
b.SetValue(Canvas.LeftProperty, (double)CurrentPosition);
b.SetValue(Canvas.ZIndexProperty, 1);
b.Background = new SolidColorBrush(Colors.Blue);
b.MouseMove += new MouseEventHandler(Border_MouseMove);
b.MouseLeftButtonDown += new MouseButtonEventHandler(Border_MouseLeftButtonDown);
b.MouseLeftButtonUp += new MouseButtonEventHandler(Border_MouseLeftButtonUp);
b.Child = img;
Layout.Children.Add(b);
UpdateLayout();
}
The image Uri is probably good because if i try to add only the border(without the image) it's still not rendering. Also i call this AddItem function from a button click event handler so initializations should not be a problem. Probably i am missing a very basic stuff here. Any ideas are welcome, thank you for your help.
Update: Ok i had something wrong with the browser cache probably, the border is added, but the image in the border isn't showing up. In the Visual Studio project i have an Images dir with the image files. Am i setting the path to them wrong?
So, now i am allowed to answer it. Well it was a newbie mistake.
The first / before Images is not needed. new Uri(#"Images/" + ImageFileName, UriKind.Relative) is correct.

Silverlight Image Cropping

Does anybody knows how to image cropping in silverlight without any library.
I have Child window and inside the child window I havev a image and this image center one rectange is there so I can panning the image to the around the rectange and selecet the perticular part of the image and this selected part I want to crop.
Also I am using WriteableBitmap and try to Crop, this will not work if correct me if I am wrong.
sheetRectangle.Children is the Image.
foreach (ucPicRect item in sheetRectangle.Children)
{
WriteableBitmap obj = new WriteableBitmap(item.imgCell.Source as BitmapSource);
obj.Crop(0,0,400,400);
obj.Invalidate();
item.imgCell.Effect = dlgcwEditPhoto.imgEdit.Effect;
item.imgCell.Source = obj;// dlgcwEditPhoto.imgEdit.Source;
}
Thanks...!!!
you can use this utility function to crop your image
public static WriteableBitmap cropImage(Image image, double[] coordonnee)
{
Image cloneImage = new Image();
cloneImage.Source = image.Source;
RectangleGeometry myRec = new RectangleGeometry();
myRec.Rect = new Rect(coordonnee[0], coordonnee[1], coordonnee[2], coordonnee[3]);
cloneImage.Clip = myRec;
TranslateTransform t = new TranslateTransform();
t.X = -coordonnee[0];
t.Y = -coordonnee[1];
WriteableBitmap wb = new WriteableBitmap(cloneImage, t);
wb.Invalidate();
return wb;
}
good luck !!

silverlight bing maps pushpin question

I'm trying to use the microsoft_maps_mapcontrol. I see how one could create a pushpin and the lat long location... but i can't figure out how to instead use an image in place of that pushpin. doesn't look like pushpin will allow using a different image. So, that being the case how do you create an image and then wire it to the proper spot. Once wired can will i be able to use an event for when that image is clicked on.
thanks
shannon
added 3/2/2010
I've looked at the example given at http://www.microsoft.com/maps/isdk/silverlightbeta/#MapControlInteractiveSdk.Tutorials.UIElements.Media.TutorialPositionPointMedia
and i must not be converting something correctly to vb.
Here is there code
Image image = new Image();
image.Source = new BitmapImage(new Uri(ImageUriValue.Text, UriKind.RelativeOrAbsolute));
double opacity;
if (double.TryParse(OpacityText.Text, out opacity))
{
image.Opacity = opacity;
}
image.ImageFailed += MediaFailed;
Point point = GetPoint();
Canvas.SetLeft(image, point.X);
Canvas.SetTop(image, point.Y);
myCanvas.Children.Add(image);
element = image;
and what i converted it to
Dim image As New Image()
image.Source = New BitmapImage(New Uri("\Images\1.png", UriKind.RelativeOrAbsolute))
Canvas.SetLeft(image, 100)
Canvas.SetTop(image, 100)
myCanvas.Children.Add(image)
element = image
Hopefully that helps in spotting what i'm not doing correctly.
thanks
shannon
Here's a code snippet that should show you how to add an image.
public void addImageToMap()
{
MapLayer imageLayer = new MapLayer();
Image image = new Image();
//Define the URI location of the image
image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("myimage.png", UriKind.Relative));
//Define the image display properties
image.Opacity = 0.8;
image.Stretch = System.Windows.Media.Stretch.None;
//The map location to place the image at
Location location = new Location() { Latitude = -45, Longitude = 122 };
//Center the image around the location specified
PositionOrigin position = PositionOrigin.Center;
//Add the image to the defined map layer
imageLayer.AddChild(image, location, position);
//Add the image layer to the map
TestMap.Children.Add(imageLayer);
}
http://msdn.microsoft.com/en-us/library/ee681895.aspx

Resources