I programming for Windows Phone 8.1. I use this way to create image and set source of image:
Dim AgreeBitmapImage As BitmapImage = New BitmapImage()
AgreeBitmapImage.setsource(New Uri("Assets/Image/Agree.png", UriKind.Relative))
//Above line gives an error
imgAccept = New Image
imgAccept.Height = 40
imgAccept.Width = 40
imgAccept.Source = AgreeBitmapImage
When I start the emulator, it doesn't work. Why? (Say error)
In Windows Phone 8.1, the resources like png should be get using ms-appx:
AgreeBitmapImage.UriSource =
New Uri("ms-appx:///Assets/Image/Agree.png", UriKind.Absolute)
Related
Within my Lightswitch desktop app (Silverlight client), I use silverPDF to create an invoice. All works well until I try to add an image (company logo).
My image is one that is saved to the database as image type (byte arrray) via the lightswitch image screen control. As far as I can tell I need to load the byte array into a memory stream then into silverPDF's XImage. Code snippet as follows:
Dim memStream As New MemoryStream(100)
memStream.Write(CompDetProp.CompanyLogo, 0, CompDetProp.CompanyLogo.Length)
Dim myimage As XImage = XImage.FromStream(memStream)
Dim x As Double = (250 - myimage.PixelWidth * 72 / myimage.HorizontalResolution) / 2
gfx.DrawImage(myimage, x, 10)
This compiles but I get an exception when run "The byte array is not a recognized imageformat."
I have also tried the following:
Dim memStream As MemoryStream = New MemoryStream(CompDetProp.CompanyLogo, 0, CompDetProp.CompanyLogo.Length)
Dim myimage As XImage = XImage.FromStream(memStream)
Dim x As Double = (250 - myimage.PixelWidth * 72 / myimage.HorizontalResolution) / 2
gfx.DrawImage(myimage, x, 10)
This second code block has the memory stream closing before it gets used - as far as I can tell.
How can I get the image into a stream that is read by silverPDF XImage before it closes and in the correct format?
After the comment from PDFsharp Expert I found that the image I was using was a .png file. I re saved the image as .jpg and the code worked. I now have an image on my invoice (although size constraints need to be played with to ensure correct fit). Thank you PDFsharp Expert.
How I can create PDF files from a list of image in WinRT. I found something similar for windows phone 8 here("Converting list of images to pdf in windows phone 8") But I am looking for a solution for windows 8. If anyone of having knowledge about this please share your thoughts with me.
Try http://jspdf.com/
This should work on WinJS, but I haven't tested it. In a XAML app you can try to host a web browser control with a jsPDF-enabled page.
ComponentOne has now released the same PDF library that they had in Windows Phone for Windows Runtime. Tho it's not open source, of course.
Amyuni PDF Creator for WinRT (a commercial library) could be used for this task. You can create a new PDF file by creating a new instance of the class AmyuniPDFCreator.IacDocument, then add new pages with the method AddPage, and add pictures to each page by using the method IacPage.CreateObject.
The code in C# for adding a picture to a page will look like this:
public IacDocument CreatePDFFromImage()
{
IacDocument pdfDoc = new IacDocument();
// Set the license key
pdfDoc.SetLicenseKey("Amyuni Tech.", "07EFCD0...C4FB9CFD");
IacPage targetPage = pdfDoc.GetPage(1); // A new document will always be created with an empty page
// Adding a picture to the current page
using (Stream imgStrm = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync("pdfcreatorwinrt.png"))
{
IacObject oPic = page.CreateObject(IacObjectType.acObjectTypePicture, "MyPngPicture");
BinaryReader binReader = new BinaryReader(imgStrm);
byte[] imgData = binReader.ReadBytes((int)imgStrm.Length);
// The "ImageFileData" attribute has not been added yet to the online documentation
oPic.AttributeByName("ImageFileData").Value = imgData;
oPic.Coordinates = new Rect(100, 2000, 1200, 2000);
}
return pdfDoc;
}
Disclaimer: I currently work as a developer of the library
For an "open source" alternative it might be better for you to rely on a web service that creates the PDF file using one of the many open source libraries available.
I think this may help you if you want to convert an image (.jpg) file to a PDF file.
Its working in my lab.
string source = "image.jpg";
string destinaton = "image.pdf";
PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);
xgr.DrawImage(img, 0, 0);
doc.Save(destinaton);
doc.Close();
Thanks.
I create a custom image in my app (by capturing ink data for example) and then want to show the generated image on Live Tile. How can I do this?
all you need to do is assign the image to the live tile template.
TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);
XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
tileTextAttributes[0].InnerText = "Hello World! My very own tile notification";
XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///images/redWide.png");
((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");
XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04);
XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode("Hello World! My very own tile notification"));
IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);
TileNotification tileNotification = new TileNotification(tileXml);
tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
The following blog post by Jeff Blankenburg can be used as a starting point for everything you want to know about Live Tiles:
31 Days of Windows 8
My app retrieves file content from remote server. File can be image or text. When the file is image it returns some string like this:
????\bNExif\0\0MM\0*\0\0\0\b\0\a\0.... and so on. As I understand it's an image but in other format (binary?).
So how can I convert that string to an image and set it to control as source?
Thanks.
I think you can do something like this:
MemoryStream ms = new MemoryStream(bytes);
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
Then if you have an Image element in XAML, say XamlImage:
XamlImage.Source = bi;
I am developing a simple code to get the image from filedialog and i want it to be displayed in picturebox. but i get error "outofmemory" with few images.
here is my code
Dim srcmap As Bitmap
srcmap = New Bitmap(OpenFileDialog1.FileName)
Dim destbit As New Bitmap(220, 220)
Dim srcRec As New Rectangle(0, 0, srcmap.Width, srcmap.Height)
Dim destRec As New Rectangle(0, 0, 220, 220)
Dim g As Graphics
g = Graphics.FromImage(destbit)
g.DrawImage(srcmap, destRec,srcRec, GraphicsUnit.Pixel)
picturebox.Image = destbit
Mobile devices have limitted resources. Up to Windows CE 5 based OS (latest currently called Windows Embedded Handheld 6.5.3) each process gets only 32MB program memory. This memory is limitted by DLLs loaded by other processes and you may have 24MB or less available for a new process.
Instead of loading whole image data, which may 15MB (5MP image) or more you should load a thumbnail representation of the image data only. It does not make sense to load 15MB image data into a pictore box of for example only 1MB pixel data.
The OpenNetCF framework offers some classes to create thumbnails using streams. Other attempts to load the data and then resize it will fail.
I am sorry, but I only have C# code examples: here is an image helper class http://code.google.com/p/intermeccontrols/source/browse/DPAG7/Hasci.TestApp.And_Controls/IntermecControls/Hasci.TestApp.IntermecCamera3/ImageHelper.cs and here is how I used it to load 5MP images http://code.google.com/p/intermeccontrols/source/browse/DPAG7/Hasci.TestApp.And_Controls/IntermecControls/Hasci.TestApp.IntermecCamera3/IntermecCameraControl3.cs:
OpenNETCF.Drawing.Imaging.StreamOnFile m_stream;
Size m_size;
/// <summary>
/// this will handle also large bitmaps and show a thumbnailed version on a picturebox
/// see http://blog.opennetcf.com/ctacke/2010/10/13/LoadingPartsOfLargeImagesInTheCompactFramework.aspx
/// </summary>
/// <param name="sFileName">the name of the file to load</param>
private void showImage(string sFileName)
{
var stream = File.Open(sFileName, FileMode.Open);
m_stream = new StreamOnFile(stream);
m_size = ImageHelper.GetRawImageSize(m_stream);
System.Diagnostics.Debug.WriteLine("showImage loading " + sFileName + ", width/height = " + m_size.Width.ToString() + "/"+ m_size.Height.ToString());
//CameraPreview.Image = ImageHelper.CreateThumbnail(m_stream, CameraPreview.Width, CameraPreview.Height);
CameraSnapshot.Image = ImageHelper.CreateThumbnail(m_stream, CameraPreview.Width, CameraPreview.Height);
showSnapshot(true); //show still image
m_stream.Dispose();
stream.Close();
}