Steam Game Icon - c#

I am making a file explorer and for the thumbnail view it requires the icon of a file. I have gotten an icon for all of the files except for steam games. I have looked around and cannot find a way to get the icon like Windows does.
Edit:
This is what i currently use to get my file icons:
public static Bitmap GetBigImage(string path, Size size)
{
Bitmap bmp;
string ext = System.IO.Path.GetExtension(path);
if (ext == ".exe")
{
Icon ico = Icon.ExtractAssociatedIcon(path);
bmp = ico.ToBitmap();
ico.Dispose();
}
else
{
if (imageType.Contains(ext.Replace(".", "")))
{
Image img = Image.FromFile(path);
bmp = new Bitmap(img, new Size(size.Width - 20, 80));
img.Dispose();
}
else
{
Icon ico = Win32.GetLargeIconForExtension(ext);
bmp = ico.ToBitmap();
ico.Dispose();
}
}
return bmp;
}
This is the path I am trying to get steam://rungameid/209170
In GetBigImage, if I see if the path contains steam:// (in either of the if statements) the method still returns no icon.

There is a Database of Steam Games here. Each entry leads to a page that includes a link to the game's icon.
Your ID leads to this page where this link points to the icon.
Note that there usually is a real icon under the field 'clienticon' and also a plain jpg strangely named 'icon'!
For an explorer type app I recommend caching those icon.
Hope this helps.

Have you tried,
Icon.ExtractAssociatedIcon
From the System.Drawing namespace?
http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon(v=vs.110).aspx

Related

Trouble Successfully Setting OpenTK Window Icon

I've been trying to set the icon for my OpenTK window by using the ImageSharp library to load the image from my device and then converting the data to a byte array which I then set as the window icon using the WindowIcon method.
Although this did set the icon to something, it doesn't look anything like it should; it should be a comical picture of my cat. However, the result was three black horizontal lines on top of a grey and pink background.
...
If anyone could help me it would be greatly appreciated :)
(I'm using Visual Studio 2019 as my IDE with, of course, the language C#, and .NET Framework 5.0)
My code:
public static byte[] ImageToByteArray(string Icon)
{
var image = (Image<Rgba32>)SixLabors.ImageSharp.Image.Load(Configuration.Default, Icon);
image.Mutate(x => x.Flip(FlipMode.Vertical));
var pixels = new byte[4 * image.Width * image.Height];
image.CopyPixelDataTo(pixels);
return pixels;
}
public Game(int width = 1280, int height = 768, string title = "Window") :
base(
GameWindowSettings.Default,
new NativeWindowSettings()
{
Title = title,
Size = new Vector2i(width, height),
APIVersion = new Version(4, 6),
Icon = new WindowIcon(new OpenTK.Windowing.Common.Input.Image(100, 100, ImageToByteArray(#"C:\Users\xenon\Downloads\BobbilyIcon.png")))
})
{
this.CenterWindow();
}
Sadly, I can't directly include images since I am a new user, so I've attached links to a couple useful images concerning my problem below:
The picture of my cat which I am trying to set as the icon:
https://i.stack.imgur.com/uEMLk.jpg
The unexpected result:
https://i.stack.imgur.com/nvpdz.jpg
Okay, so apparently I'm a bit dumb. Turns out that when I am setting the icon, using the WindowIcon function, the height and width of the icon must match that of the image being used, which makes a lot of sense now that I think about it. I thought it was some incompatibility between the ImageSharp library used to load the image to memory and copy the data to the byte array and OpenTK.

Washed out colors in PictureBox

When I show a specific image in a PictureBox (or Cyotek's ImageBox in my case, doesn't matter), the color gets a little washed out. Most images displays correctly but some few images gets washed out.
Here's what it looks like:
The original image
Opened in Windows Photo Viewer
Opened in my application
I tried loading the image in 3 different ways, but same result:
Image image = GetImage(OPEN);
imgBox.Image = image;
public Image GetImage(string path)
{
Image image = null;
//image = Image.FromFile(#"D:\Visual Studio\pictures\pokemon.jpg"); // washed out colors
try
{
using (FileStream file_stream = new FileStream(path, FileMode.Open, FileAccess.Read)) // washed out colors
{
MemoryStream memory_stream = new MemoryStream();
file_stream.CopyTo(memory_stream);
image = Image.FromStream(memory_stream, false, false);
file_stream.Dispose();
}
}
catch
{
try
{
FIBITMAP picture = FreeImage.LoadEx(path); // washed out colors
Bitmap bitmap = FreeImage.GetBitmap(picture);
image = bitmap;
FreeImage.Unload(picture);
}
catch { }
}
return image;
}
Anyone know why this is? Maybe some specific tag in this image that Windows and PictureBox handles differently?
You should use Image.FromStream() and pass true for the useEmbeddedColorManagement argument to ensure that any metadata for color management is used.

Save rotate image onto server

I want to save rotate image onto the server
I found some solution but its not working..
UPDATE
Image path is in xml..
here is the code:
public Boolean saveRotateImg(string path)
{
string new_path="/Job_Files/"+Job_ID+"/"+GroupName+"/Images/"+path;
using (Image image = Image.FromFile(new_path))
{
//rotate the picture by 90 degrees and re-save the picture as a Jpeg
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
System.IO.File.Delete(path);
image.Save(output, System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
}
}
Can anyone suggest how to do that or any other way for that..
Based on the comments above it should be something like this:
public Boolean saveRotateImg(string path)
{
string new_path="/Job_Files/"+Job_ID+"/"+GroupName+"/Images/"+path;
// Load the image from the original path
using (Image image = Image.FromFile(path))
{
//rotate the picture by 90 degrees and re-save the picture as a Jpeg
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
// Save the image to the new_path
image.Save(new_path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
System.IO.File.Delete(path);
}
Though you will have to make sure that the variables path and new_path contain the full path + filename of the image.
EDIT: I've removed the image.Dispose() as the using will take care of this. Also I've replaced the System.IO.File.Delete(path) call to the end of the routine, not sure if this is required, but in this case it will never interfere with the usage of the image.

PictureBox and Dispose

I must delete an image file if it already exists (overwriting it) while a PictureBox is showing the same.
However If I try to delete the file it's blocked by PictureBox.
So I write the following code:
if (File.Exists(file))
{
Image _tmp = (Image)current_pic.Image.Clone();
current_pic.Image.Dispose();
current_pic.Dispose();
File.Delete(path);
current_pic.Image = _tmp;
current_pic.Image.Save(file, ImageFormat.Jpeg);
}
else
current_pic.Image.Save(file, ImageFormat.Jpeg);
and the Image on filesystem is deleted thanks to pic.Dispose() but the Image is not
more showed inside the PictureBox.
Maybe does Dispose() method invalidate PictureBox?
You can read a image into the picture box without locking it as shown below
Image img;
string file = #"d:\a.jpg";
using (Bitmap bmp = new Bitmap(file))
{
img = new Bitmap(bmp);
current_pic.Image = img;
}
if (File.Exists(file))
{
File.Delete(file);
current_pic.Image.Save(file, ImageFormat.Jpeg);
}
else
current_pic.Image.Save(file, ImageFormat.Jpeg);
I have updated the code to even support the save operation.
While the previous code supported the delete even after linking the images. The stream was closed and this while saving resulted in a GDI+ error.
The newly updated code meets all your requirements as follows
Allowing a delete of the file while the images is linked
Save of the Image using the Image property in the Picturebox control

Windows Phone generating Tile - cant seem to make it transparent

I am generating a tile from within my application and when its displayed the background image that its using as the basis fro the the tile has lost its transparency (and therefore its not picking up the theme color.
The background image has an icon on it and is transparent - when I use it as the standard Tile (i.e. not generate an image with it ) thens its fine and the transparency is all good..
But when I use it as the background image and add my own container over it then its not transparent the background is showing as black.
The relevant code is as follows:
// [...]
var container = new Grid();
if (isWide)
{
container = CreateContainerWide(tileInfo);
}
else
{
container = CreateContainerMedium(tileInfo);
}
// Add the background
container.Background = new ImageBrush
{
ImageSource = background,
Opacity = opacity
};
// Force the container to render itself
container.Arrange(new Rect(0, 0, width, height));
// Write the image to disk and return the filename
return WriteShellTileUIElementToDisk(container, baseFileName);
}
static string WriteShellTileUIElementToDisk(UIElement element, string baseFileName)
{
var wb = new WriteableBitmap(element, null);
// All content must be in this sub-folder of IsoStore
string fileName = SharedImagePath + baseFileName + ImageExtension;
var stream = new IsolatedStorageFileStream(fileName, System.IO.FileMode.Create, Isf);
// Write the JPEG using the standard tile size
// Sometimes the bitmap has (0,0) size and this fails for unknown reasons with an argument exception
if (wb.PixelHeight > 0)
wb.SaveJpeg(stream, wb.PixelWidth, wb.PixelHeight, 0, JpegQuality);
else
{
Debug.WriteLine("Can't write out file because bitmap had 0,0 size; not sure why");
// indicate that there is an issue
fileName = null;
}
stream.Close();
// Return the filename
return fileName;
}
Doesn't seem to make any difference as to what I set the Opacity of the ImageBrush to.
If I used a solid color rataher than a transparent layer then its all fine. Somehow the creation of the png is losing the transparency.
Any Ideas?
thanks
This answer might be helpful. Instead of saving a JPG you can save the image as a PNG which does support transparency. The library mentioned in the answer is quite useful.

Categories

Resources