How to display a different text for each image? - c#

I have a problem about the foreach instruction and a description for each image.
Right now, when the user selects an image from the list, the next message occurs (see image1)
What I want is to change this text with a different one for each image.
I've also created a class called WineModel and its code is posted below.
What should I do to display a different description for each image?
One of my ideas would be to create a vector like in this link and to display a different message for each image from the position of the vector.
var files = Directory.GetFiles(#".\GalleryImages");
foreach (var file in files)
{
FileInfo fileInfo = new FileInfo(file);
WineModel wineModel = new WineModel();
wineModel.Image = new Uri(file, UriKind.Relative);
wineModel.Description = file + "Ana are mere" +
Environment.NewLine + "text text text text text text text text text text text";
wineModel.Price = new Random().NextDouble();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = wineModel.Image;
bi.EndInit();
var button = new KinectTileButton
{
Label = System.IO.Path.GetFileNameWithoutExtension(file),
Background = new ImageBrush(bi),
Tag = wineModel
};
this.wrapPanel.Children.Add(button);
}
http://i58.tinypic.com/nbvhu8.png
http://msdn.microsoft.com/en-us/library/ttw7t8t6.aspx

Related

Printing Text and Image in 1 PDF File

I have a problem with printing data and image in PDF. I use the code below and it print image and data separately. But I want them to be in one PDF, how can I do this?
PrintDialog export = new PrintDialog();
string data = "data";
System.Windows.Documents.FlowDocument flowDoc = new System.Windows.Documents.FlowDocument(new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(data)));
System.Windows.Documents.IDocumentPaginatorSource source = flowDoc;
var result = export.ShowDialog();
if(result == true)
{
export.PrintVisual(souradnySystem, "Visual");
export.PrintDocument(source.DocumentPaginator, "Text");
}
Add the image to the FlowDocument before proceeding to print.
Assuming "souradnySystem" is your image (System.Windows.Controls.Image), it will be like the following:
string data = "data";
FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run(data)));
flowDoc.Blocks.Add(new BlockUIContainer(souradnySystem));

How can I save this image as HD as possible?

I am trying to modify my song's metadata. I got this to work, but if the user has not specified an album art image I automatically draw one from a picturebox holding the album image. The returned image is really blurry- Is there any way I could make it as high definition as possible? Here is the part of my code where I handle that:
if (isDir == false){
IPicture art2 = new TagLib.Picture(new TagLib.ByteVector((byte[])new System.Drawing.ImageConverter().ConvertTo(pictureBox1.Image, typeof(byte[])))); //I make the new picture here.
TagLib.File file2 = TagLib.File.Create(Properties.Settings.Default.NowPlayingPath);
file2.Tag.Title = SongBox.Text;
file2.Tag.AlbumArtists = artist;
file2.Tag.Genres = genre;
file2.Tag.Year = Convert.ToUInt32(YearBox.Text);
file2.Tag.Composers = composers;
file2.Tag.Pictures = new IPicture[1] { art2 };//I set the picture here.
file2.Save();
MessageBox.Show("You'll need to reload your song to continue listening to it.", "Settings saved.");
this.Hide();
}
}
Try to use MemoryStream to get image as byte array:
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] buff = ms.GetBuffer();
IPicture art2 = new TagLib.Picture(new TagLib.ByteVector(buff));

Fast way to check is image exists in assets in Windows Phone

My application for Windows Phone 8.1.
I need to find a way to check image aviability in assets resources in my application.
At first, I had following solution:
var package = Windows.ApplicationModel.Package.Current.InstalledLocation;
var folder = await package.GetFolderAsync("Assets\\Makes");
var files = await folder.GetFilesAsync();
var result = files.FirstOrDefault(p => p.Name == imageName);
if (result != null)
{
Uri imageUri = new Uri("ms-appx:///Assets/Makes/" + imageName);
Image img = new Image();
BitmapImage bi = new BitmapImage(imageUri);
img.Source = bi;
btn.Content = img;
}
else
{
TextBlock label = new TextBlock();
label.Text = text;
btn.Content = label;
}
It works. But, unfortunately, very very slow.
Anyway, next part of code working even in case if asset is not existing:
Uri imageUri = new Uri("ms-appx:///Assets/Makes/" + imageName);
BitmapImage bi = new BitmapImage(imageUri);
In case if file not existing, the image is empty, but not null.
Is there are any good way, to check, if image created empty from resource?
Or a really fast way to check existing of packaged resource file?
Thank you

Converting 2 page .tif file to .jpg

I am having an error when converting/reading 2 pages .tif files . What is the right approach for this?
Here's the error:
ImageMagick.MagickCoderErrorException: Magick: C:\DigitalAssets\sample.TIF: Null count for "Tag 33426" (type 4, writecount -3, passcount 1). `_TIFFVSetField' # error/tiff.c/TIFFErrors/561
at ImageMagick.MagickImage.HandleReadException(MagickException exception)
at ImageMagick.MagickImage.Read(String fileName, MagickReadSettings readSettings)
at Digital_Asset_Converter_Service.Service.EPSFolderWatcher_Created(Object sender, FileSystemEventArgs e)
Here's the code:
string fileName = #"C:\DigitalAssets\sample.tif";
using (MagickImageCollection image = new MagickImageCollection())
{
MagickReadSettings settings = new MagickReadSettings();
// settings.ColorSpace = ColorSpace.RGB;
settings.Density = new MagickGeometry(300, 300);
//settings.FrameIndex = 0;
// settings.FrameCount = 1;
image.Read(fileName,settings);
}
Your image contains a corrupt tiff tag that causes a MagickCoderErrorException. We made a change to ImageMagick that will allow you to ignore a specific tiff tag. Below is an example that will prevent the MagickCoderErrorException:
using (MagickImage image = new MagickImage())
{
image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426");
// Or if you want to ignore multiple tags:
image.SetDefine(MagickFormat.Tiff, "ignore-tags", "33426,33428");
MagickReadSettings settings = new MagickReadSettings();
// settings.ColorSpace = ColorSpace.RGB;
settings.Density = new MagickGeometry(300, 300);
image.Read(fileName, settings);
}

Save images from listview to a folder

I had this listview and a button. There are also several images inside the listview. I want to save the images from the listview inside the folder when the button is pressed. And I don't know how to do it. Could you please help me out? Thanks. This is the code I use to insert images to the listview.
OpenFileDialog opend1 = new OpenFileDialog();
opend1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
opend1.Multiselect = true;
if (opend1.ShowDialog() == DialogResult.OK)
{
listView1.View = View.LargeIcon;
imageList.ImageSize = new Size(100, 100);
for (int c = 0; c < opend1.FileNames.Length; c++)
{
Image i = Image.FromFile(opend1.FileNames[c].ToString());
Image img = i.GetThumbnailImage(100, 100, null, new IntPtr());
imageList.Images.Add(img);
}
listView1.LargeImageList = imageList;
ListViewItem lstItem = new ListViewItem();
lstItem.ImageIndex = imageList.Images.Count-1;
listView1.Items.Add(lstItem);
listView1.Refresh();
}
For each image in your image list (imageList.Images) call this (with your own supplied directory and file name):
img.Save(#"C:\MyImage.jpg", ImageFormat.Jpeg);
foreach (Image image in listView1.LargeImageList.Images)
{
string filename = ""; // make this whatever you need...
image.Save(filename);
}

Categories