Constructing HICON with multiple images from memory pixel data - windows

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.

Related

How can I use low-level functions (not imread) to read a grayscale image?

I'm trying to use low-level functions (fopen and fread) to read a grayscale image of type uint16 in TIFF format as follows:
fid = fopen(filepath,'r');
img = fread(fid,[ncolms, nrows], 'uint16=>uint16')';
The obtained image matrix is different from that obtained by simply using imread:
img = imread(filepath);
The resulting images are shown below (the left is by fread and the right is by imread):
In addition to the obvious intensity difference, one may also note that fread image has some artifacts in the top edge of image. I think this must be due to their different mechanisms of reading images.
I want to know how to use such low-level functions as fopen and fread to read images (grayscale, not binary), equivalently to using imread, if they can.
Those "artifacts" you're seeing are likely the header and tag data stored in the file before the image data. I would suggest taking a look at this TIFF File Format Summary. It will tell you exactly how to read all this extra information, if you really want to do it yourself. Note that some of this extra tag information (i.e. ImageHeight, ImageWidth, BitsPerSample, SamplesPerPixel, etc.) will be useful in determining exactly how to read the image data correctly, and thus match the image you get from the imread function.

Can I edit the thumbnail image inside JFIF files?

Can I edit the thumbnail image inside JPG/JFIF files?
If this is possible--how so (using what utility)?
The end result needs to be that the thumbnail image "can" be a wholly different image than the jpeg.
Thank you much,
Michael
Typically, thumbnails are uncompressed RGB data. You locate the marker, see where the thumbnail's width/height are marked, then modify the byte stream following it. the stream is of length width*height*3 bytes.
If it's indexed, you'd have to overwrite the palette and the index entries. Just look for the APP0 marker, start modifying it.
A compliant EXIF thumbnail image must fit in the 64K APP1 marker and is usually compressed as JPEG (unlike what #Karthik says). The thumbnail image is independent of the main image and can easily be changed since it is inside a marker segment that doesn't affect the main image. The JPEG marker segments are basically a linked list of independent binary blobs with 2-byte identifiers (e.g. FFE1 in this case) and 2-byte lengths. You can swap out one for another and you won't "break" the file. There is no checksum or other mechanism that verifies the entire file data integrity. I'm not familiar with libraries to edit this information, but you can do it in a small amount of code that only has to parse the marker blobs type and length without knowing their contents. You can also do it the "quick and dirty" way by ensuring that your new thumbnail is no larger than the original and then you can just write it in it's place without moving the other parts of the file around. The marker length is not checked against its contents, so unused space is ignored.

Best practices for creating thumbnails with GAE's Image API

For each photo in my datastore, I'm creating 3 thumbnails (small, medium, and large). I'm having a hard time figuring out what API functions to use on the original photos to get a balance between quality and file size for the thumbnails. The file size for the thumbs always seems to be too large.
GAE's Image API has many options for images (such as im_feeling_lucky(), converting from PNG to JPEG, and adjusting JPEG quality) and I'd like to know what functions to use and in which order to achieve the optimal setting for these thumbnails.
The easiest way to do this is simply to use get_serving_url to get a public URL for a scaled version of the image you can use as a thumbnail. This removes the need for you to create and separately store thumbnailed images.

How to access a different formats within an icns file (Apple Icon Image format)

does anyone know how to access different formats of an icns file?
For example this file contains multiple sizes of the same icon:
In some cases I just want the large one and in other cases I want the small one.
I couldn't find something in Cocoa.
An NSImage is a container for NSImageReps. When you load an icns file, you get an image containing an NSBitmapImageRep for each size in the file. You can iterate over the image’s representations property to access them. (Also, the image will automatically choose the most appropriate rep when drawing.)

Convert BITMAP to PNG using IImage interface on Windows Mobile

I've got a handle to a BITMAP structure (HBITMAP) in a Windows Mobile application -- I'd like to save the bitmap as a PNG file, using the IImage interface if possible. (There's no BMP file in this situation, the BITMAP is only in memory).
It looks like I could use IImagingFactory's IImagingFactory::CreateImageEncoderToFile method to save the file but I think I'd first have to get the BITMAP converted into "IImage" format.
Any ideas on how to do this with native code?
Use CreateImageFromStream to read in your BITMAP data, that gives you an IImage.
Edit:
I did a little more research on this. There are a couple paths, but I think the easiest is to:
create a DIBSECTION and blit your bitmap to it.
Create a BitmapData instance pointing to the DIBSECTION for the image data.
Call CreateBitmapFromBuffer to generate an IBitmapImage interface
Push the IBitmapImage (which is an IImage) through your encoder.

Resources