Microsoft deploys free Image Library with Visual Studio.
At following location, you can find .png files which contain more than one icon in it.
c:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary_Common Elements\Actions\
Is there any way to access particular icon from file programmaticaly, or I have to edit those files in some photo-tool and save every icon separately ?
Edit:
.png files don't have more than one logical icon in it (.ico files can have)
.png icons shipped with VS Image library don't follow any kind of pattern so thay can not be easily utilised by code (mipmapping). They will have to be edited in some graphic tool and then saved to separated files
Icon files (can) contains several images inside of them but you don't need to extract them.
The idea is that at runtime the best icon is severed (like mipmaping in 3d).
If you use the Graphics.DrawIcon(Icon, Rectangle) then the best icon will be choose for you.
or you can use Paint.NET with the Icon addin to extract the exact size.
Related
The default structure for icons in a Xamarin application for an android app at the moment is:
folders:
mipmap-hdpi
mipmap-mdpi
mipmap-xhdpi
mipmap-xxhdpi
mipmap-xxxhdpi
And within each of these folders there are two PNG images that are named:
icon.png
launcher_foreground.png
I have searched for a couple of hours to find some sort of generator that can generate the "launcher_foreground.png" image. All the generators I have seen only generate ONE image in each of these folders.
According to Xamarin, including two images in each of these folders is "good practice" but every generator I have seen does not generate icons this way.
Is there a tool that anyone knows of that can generate each of these images in the format stated above?
If not, is there a way I can use a single SVG file as an icon? Since an SVG file can scale dynamically and has been able to do so for a very long time. Is there a better way to do this?
You cannot use an svg as your app icon because Android doesn't support that, but you can resize your images (svg or png) automatically to the Android, iOS, UWP standard required sizes using ResizetizerNT package.
Download and Install the Nuget Package in all your projects (shared and native).
Add your image to the shared project, and set it build action to "SharedImage" (this build option will only be available after package is installed).
In your shared project .csproj file, specify the BaseSize property for your image:
It should correspond to the x1 size or in Android the mdpi size 48,48 source and for the second one 108,108.
<ItemGroup>
<SharedImage Include="icon.svg" BaseSize="48" />
<SharedImage Include="icon.svg" BaseSize="108" Link="launcher_foreground.png" />
</ItemGroup>
Output (resized) images will be found in folder: obj\[Debug|Release]\100\resizetize\r\
Resources
Documentation: How to use it
Author explanation video
Official repo
I am trying to program an automatic Resource Loader for my project and so it is going well. But I am stuck on the loading of the sprites. I used this for checking the file exists
if (File.Exists(contentManager.RootDirectory + "/Sprites/" + spriteName + ".png"))
However it never finds the file, even though the file exists in the Content of the project. I have checked the folders and found that the .pngs are replaced by .xnb files. So I tried changing the file extension and then was given an error in the Sprite Load function
return contentManager.Load<Texture2D>(assetName);
It only happens if I change it from being a typical image file (png, bmp, etc). Can someone explain why this is the problem and how I can get around this? I have had no experience in the xna file extensions and can not find the answers I need. What I want is to load a new image into the project providing it exists in the Content Directory after compile
While on the topic, will the Sounds and Music be effected by the Compiler?
When you use a content project, the resources are imported, processed and write to disk again as xnb files.
If you want to dynamically load resources you have to compile files on the fly through the content builder or avoid using the content project.
Microsoft provides examples like this to load content dynamically: http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_2
if you want to distribute the application, the runtime xna is not enoigh, you need full xna framework and visual studio installed to work.
if you want the original files in the content project, you have to change their "copy to output folder" property to "copy always", and realize that the compiled results will be at "project folder\bin\debug\content"
I'm trying to add images to my tree nodes (ImageList.Add()), but just can't figure out a nice way of doing it.
I've read from MSDN help I should use System.Drawing.Image.FromFile(path). But cannot just get a file somewhere.
I'm building a DLL, and want it to be a single file, no bitmaps being copied together with it.
So I've read I should add Image files to the project and mark them with Build Action as "Resource".
Ok, but where do I get them??? I saw people using it in XAML files, but I don't have that.
Saw people using Resources.SomeName, but can't find those Resources class.
So....How do I do it?? I've got the files marked as resources, just need to add them to the ImageList.
By the way, I'd love to use the path relative to the Code File that is adding the images to the ImageList. But if not possible, just relative to the assembly root.
If you want to use file paths, for items that are in your project, you must set the "Copy to Output Directory" property to "Copy Always" or "Copy if newer", otherwise it won't be in the bin folder, and then you'll be trying to pass a path to a file that doesn't exist. Build action isn't all that important in this scenario.
If you want to use compiled resources, and reference them via the Resources object, see the rest of my answer. I assume you are using Visual Studio, 2005 or later.
To add an image as a compiled resource to a clean Windows Forms project, so that you can access it via Resources.SomeName do the following:
In Solution Explorer, under the windows forms project (mine is called WinFormsApplication1), expand the "Properties" folder. By default this folder should contain: AssemblyInfo.cs, Resources.resx, Settings.settings.
Double-click on the Resources.resx file. This will open an editor for it. You'll probably see a table of strings, with columns "Name", "Value", "Comment".
Click the drop-down arrow on the "Add Resource" button, and select "Existing File", which will allow you to browse to the image you want to add.
You should now see the image appear in a gallery of sorts. Mine has the name TestImage
Now when you edit the code (mine is Fom1.cs), I can access the image as a System.Drawing.Bitmap as Properties.Resources.TestImage.
To my mind, this is the best way to do images that you want compiled into the application. If you want user-added images, you'll need to use OpenFileDialog, or something like that to get your file path. Then the Image.FormFile() will be what you want.
I am using Visual C# 2010 Express. I would like to put .dotx or Word Template files into the Resources folder of my application and when it is installed, output the files to a different directory preferably C://Myfolder/. I couldn't find anything about it here. Are there any ways to solve this?
Why would you want this as a resource? Why not bundle it as part of the installer package which can work out where to put the file when your application is installed?
Click on Resources (in "Properties"), and then on the arrow next to "strings" and choose "files".
Then drag the file in and name it. then use:
Properties.Resources.fileName;
which will be a byte[], and save it using:
File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + #"\filename", Properties.Resources.fileName);
How can I assign an external image into the PictureBox in Visual Studio 2008 ?
Typically, When we use ChooseImage in PictureBox , Visual Studio adds the image to the exe file and it causes increasing exe file's volume, I wanna add the image from a directory beside the exe file.
Is it possible in Visual Studio 2008?
P.S:
I don't want add the image with C# code, because VS2008 doesn't show it in developing time.
I think you can do this in C# code using the Image.FromFile method. As long as the C# code is in the initialization of the form / control, it should run at both design time and run time.
You can use Linked resources.
When you add a linked resource, the
.resx file that stores your project
resource information includes only a
relative path to the resource file on
disk. If you add images, videos, or
other complex files as linked
resources, you can edit them using a
default editor that you associate with
that file type in the Resource
Designer. When you add an embedded
resource, the data is stored directly
in the project's resource (.resx)
file. Strings can only be stored as
embedded resources.embedded resources.
MSDN on Linked vs. Embedded Resources
P.S. I however still don't get why would you need it—even if .exe doesn't get bigger, the whole app package would have a bigger size, wouldn't it?
Best,
Dan
If this is WinForms, it's better to just set the ImageLocation of the PictureBox to the path to your image. Do this from the designer to have it show at design time.
You can get images from Resources
pictureBox1.Image = Properties.Resources.[image name];
see How to embed and access resources by using Visual C#
Misread the question OP asked to load without using the Resources.
you will need to do
Image.FromFile("c:\\image.bmp")
If image if a JPEG then You can cast it to Bitmap
Bitmap myJpeg=(Bitmap) Image.FromFile("myJpegPath");
OR,
System.Drawing.Image loadImg = System.Drawing.Image.FromFile("c:\\image.JPG");
loadImg.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);