LoadImage (LoadIcon) from ICO file containing multiple icons - winapi

I'm trying to load and draw an icon from an .ICO file that contains multiple icons. I can't figure out how to load a specific icon. I'm using LoadImage as in the following code
{
char *iconfile="myicon.ico";
int w=72,h=72;
hIcon = LoadImage( hMainInst, iconfile, IMAGE_ICON, w, h, LR_LOADFROMFILE );
}
This works Ok but the only way I can see to select a specific icon is by size, e.g., 72x72 in my example. It seems to load the first 72x72 icon in the file. The problem is that there are multiple 72x72 icons in the file.
How do I load an icon other than the first?

Related

Xamarin SKEncodedImageFormat Jpeg background added

I'm coding in Xamarin with SkiaSharp libraries for UWP (eventuallay Android but not ios) with VS 2019
With this code
SKBitmap signature = SKBitmap.Decode(canvasImg.Encode());
using (var image = SKImage.FromBitmap(signature))
using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 80))
{
// Save data to a stream
using (var streamSign = File.OpenWrite(Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path + "\\work\\Models", "signature.jpg")))
{
data.SaveTo(streamSign);
}
}
I get a jpg file of my canvas. This is working perfectly. The issue is the image format defined with this line:
SKEncodedImageFormat.Jpeg
I need jpg format (and absolutely not png). The issue is this converter add me a black background and the black draws are invisible.
Anyone know how can i set the background added white ?
There are two possible workarounds
Convert the image to Png type and add a transparent background on it .
Refer to Adding transparency to a SKBitmap image results in black background .
Since there is no option of Jpg for SKEncodedImageFormat , we could use external tools(like paint , photoshop) to transfer the image to Png or Jpeg type .
Refer to https://social.msdn.microsoft.com/Forums/en-US/b466c566-6666-4cc9-9cdc-88d8c0032e2b/adding-transparency-to-a-skbitmap-image-results-in-black-background?forum=xamarinlibraries

How to fetch file icons of any files in OS X using Cocoa?

I am writing a Mac app in which I list directory contents i.e. files /folders in that directory.
Now, I want to show thumbnails of the various file types of that directory. Files can be image files, pdf, psd, etc.
How do I fetch icons of any file type in Cocoa?
Thanks!
An application bundle usually has icons in a file that vary in size, so we can specify which version of the icon we require. For example
const int size = 64;
const char* filePath = "pathToFileOrAppBundle";
NSString* nsfilePath = [NSString stringWithUTF8String:filePath];
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFile:nsfilePath];
// set the image size
[image setSize: NSMakeSize(size,size)];

Can I load a 48x48 icon file (.ico) in a VB6 form?

I have icons (.ico) in my vb6 application. They are of various dimension 16x16 and 32x32.
I want all the icons to be converted to 48x48 256 image format. Can I load a 48x48 icon file (.ico) in a VB6 form?
I want to know if VB6 support any other image format apart from .ico files?
Thanks
VB6 is capable of using icon files (.ico), including icon files with 48x48 pixel icons. I presume you were referring to Icons that can be assigned to forms for the purpose of displaying them on their title bars, in the far top-left corner. This can be done by assigning an Icon file to each form's Icon property during design time; or at run time, usually from either an ImageList control or Resource file (.res). However, with the exception of some Cursor files (.cur), VB6 is not capable of displaying an image for the same purpose, using another file format other than .ico (.bmp, .gif, .jpg, etc. cannot be used).
Icon images can also be used to display images elsewhere on forms, such as through the use of the PictureBox and Image controls.
Please note that there is no need to convert multiple icons to a particular format, as single Icon files (.ico) are capable of storing multiple icons of different dimensions and colour depths. When multiple icons are present within a program's icon resource, Windows Explorer will display the appropriate icon dimension for a particular file / folder view. For example, a 16x16 pixel version of the icon will be shown in "Small Icon", "Details" and "List" views, while a 48x48 pixel version will appear when the view is set to "Medium Icons". When a particular version of an icon is not available, Windows Explorer will usually try to use one of the other versions that is closest to what needs to be displayed for a particular view, which may involve stretching an icon to a larger or smaller size. Pixels of colours not able to be displayed from a high colour (24 bit) icon in a 256 colour mode, will be converted automatically to their closest equivalents, from a default system colour palatte. The disadvantage of the absence of multiple versions of the same icon, is that the quality of the icons will be reduced in particular file / folder views.

Constructing HICON with multiple images from memory pixel data

is there a Win32 API to construct a HICON handle that contains icons in multiple sizes from pixel data stored in memory? I know that I can construct single icons from memory pixel data using CreateIconIndirect() but these icons will always contain just one size but I want to construct a single HICON handle that contains icons in 16x16, 24x24, 32x32, 48x48 and 256x256 for use with RegisterClassEx().
I know I could simply use a resource icon or load an external *.ico but that's all not possible for my specific case. I need to be able to construct this multiple image HICON from memory pixel data.
The only solution that comes to my mind is to create a temporary *.ico file on disk and then load it using LoadIcon() but that is not a nice solution.
That's why I'd like to ask if there's an API to construct a multi-image HICON from memory pixel data?
Thanks!
No there is not. An HICON contains a single image. There is no such thing as a multi-image HICON.
You can supply two separate icons when you call RegisterClassEx. You supply both large and small icons in the WNDCLASSEX structure. Which is all you need because the only icons that are associated with a window are the large and small icons.

Display TIF image in a window using Win32

I'm new in programming a Win32 program. I want to display a tif image in the window, but I only found ways to display bitmap image. Does anyone got idea about how to display a tif image? Thanks.
Use Gdiplus::Bitmap class to load TIFF image. Then, get HBITMAP from it by calling GetHBITMAP.

Resources