CF - How do i access a .gif in my Resources folder - compact-framework

I have added a simple .gif file into Resources folder in my project.
Now i have created a user control with pictureBox.
How can i add the .gif to pictureBox.Image = new Bitmap (path).
What is the path in this case?
thanx !

I think you can do it in the following way:
// Create a MemoryStream from the .gif file resource
MemoryStream ms = new MemoryStream(YourApplicationName.Properties.Resources.GifFileName);
// Instantiate a new Bitmap using the created MemoryStream
pictureBox.Image = new Bitmap(ms);
Not completely sure if this works (cannot test it at the moment) but it should point you in the right direction.

Related

How to set background image to shell or composite in SWT

public class createShell{
System.out.println("Inside shell create");
display = new Display();
shell = new Shell(display);
shell.setSize(990, 590);
shell.setLayout(new GridLayout());
Composite comp = new Composite(shell, SWT.NO_FOCUS);
comp.setBounds(10, 10, 720, 400);
}
I have existing code like this. Need to set a background image to shell. How to give relative path of image.
The folder structure of plug-in(com.vcc.rac.ks5lmpp) is as per image.path The code file is in package inside src folder(plugins\com.rac.ks5lmpp\src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\createShell.java)
There exists a image folder(plugins\com.rac.ks5lmpp\src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\images) in which the image is there which I want to pass as background.
Image size is of 676X324 of PNG type.
Thanks in advance.
You use FileLocator in an Eclipse plug-in to find resources in the plug-in.
Bundle bundle = FrameworkUtil.getBundle(getClass()); // Or some other way to find the current bundle
URL url = FileLocator.find(bundle, new Path("path within the plugin"));
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
shell.setBackgroundImage(image);
Note: You should arrange to dispose of the image when the shell closes.
Be sure that the build.properties for the plug-in includes the images.
FileLocator is org.eclipse.core.runtime.FileLocator.
Path is org.eclipse.core.runtime.Path (not the java.nio.file Path)
ImageDescriptor is org.eclipse.jface.resource.ImageDescriptor

Create PDF file with images in WinRT

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.

access image outside the root folder in silverlight

Uri uri = new Uri("" + metric.Image, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
ImageMetric.Source = imgSource;
i have this code
in database im saving the image under path /UploadedImages/greenarrow.png
UploadedImages and my solution folder is placed in E drive.
But different folders.
how to access it ?
Please help me
i finally found the answer
while you are hosting the website in iis ,you can create a images folder in it and save the images from database
so that you can browse the link and find the image.
Uri uri = new Uri("http://www.abc.com"+fieldname.Image , UriKind.RelativeOrAbsolute);
ImageSource imgSource = new BitmapImage(uri);
ImageMetric.Source = imgSource;

Binary to image in Windows Phone 7

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;

Displaying Tiff files in SSRS reports

I have a requirement to be be able to embed scanned tiff images into some SSRS reports.
When I design a report in VS2005 and add an image control the tiff image displays perfectly however when I build it. I get the warning :
Warning 2 [rsInvalidMIMEType] The value of the MIMEType property for the image ‘image1’ is “image/tiff”, which is not a valid MIMEType. c:\SSRSStuff\TestReport.rdl 0 0
and instead of an image I get the little red x.
Has anybody overcome this issue?
Assuming you're delivering the image file via IIS, use an ASP.NET page to change image formats and mime type to something that you can use.
Response.ContentType = "image/png";
Response.Clear();
using (Bitmap bmp = new Bitmap(tifFilepath))
bmp.Save(Response.OutputStream, ImageFormat.Png);
Response.End();
I have been goggling fora solution on how to display a TIFF image in a SSRS report but I couldn't find any and since SSRS doesn's support TIFF, I thought converting the TIFF to one of the suppported format will do the trick. And it did. I don't know if there are similar implementation like this out there, but I am just posting so others could benefit as well.
Note this only applies if you have a TIFF image saved on database.
Public Shared Function ToImage(ByVal imageBytes As Byte()) As Byte()
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(imageBytes)
Dim os As System.IO.MemoryStream = New System.IO.MemoryStream()
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
img.Save(os, System.Drawing.Imaging.ImageFormat.Jpeg)
Return os.ToArray()
End Function
Here’s how you can use the code:
1. In the Report Properties, Select Refereneces, click add and browse System.Drawing, Version=2.0.0.0
2. Select the Code Property, Copy paste the function above
3. Click Ok
4. Drop an Image control from the toolbox
4.1. Right-Click the image and select Image Properties
4.2. Set the Image Source to Database
4.3. In the Use this field, Click expression and paste the code below
=Code.ToImage(Fields!FormImage.Value)
4.4. Set the appropriate Mime to Jpeg
Regards,
Fulbert
Thanks Peter your code didn't compile but the idea was sound.
Here is my attempt that works for me.
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
Response.Clear();
Bitmap bmp = new Bitmap(tifFileLocation);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
}