Using .png files instead of using .ico files in windows programs - png

hi I have a collection of nice .png files....
meanwhile, I'm developing a win-based software and need some .ico files as icons for toolbar buttons and ....
Is there any way to use .png file as an icon ? or what?
Thank you

As a workaround you can use IrfanView to convert your *.png file to *.ico file (or any other image to ico) & use it.
http://www.irfanview.com/main_download_engl.htm

You can simply convert the images to ico files online Ico Convert.

If you are using .NET this is not a real problem for you, because afaik PNG support is already build in. You are probably talking about native C/C++ development with GDI/win32?
To my knowledge you will not accomplish this by simply using GDI. There are a couple of options where you can set ONE color as transparent then load a simple BMP/JPEG and do some BITMAP tricks however using ICO/GIF will be far easier for this.
What you are probably looking for is a working GDI+ example which will use a PNG with alpha channel? This is just an excerpt and I left out the whole mess loading external functions from a DLL part, but maybe this will help you:
static GpImage *background = NULL;
GDIPLOADIMAGEFROMSTREAM GdipLoadImageFromStream;
GDIPLUSSTARTUP GdiplusStartup;
GDIPPLUSSHUTDOWN GdiplusShutdown;
GDIPCREATEFROMHDC GdipCreateFromHDC;
GDIPDELETEGRAPHICS GdipDeleteGraphics;
GDIPDRAWIMAGEI GdipDrawImageI;
GDIPDRAWIMAGERECTI GdipDrawImageRectI;
GDIPLUS_STARTUP_INPUT GdiplusStartupInput;
void LoadPNG(GpImage **image, int resource, HMODULE hInstance)
{
HRSRC resrc;
LPSTREAM lpstr;
HGLOBAL hPng;
LPVOID fByte;
GpImage *img = NULL;
resrc = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(resource), TEXT("PNG"));
hPng = LoadResource(GetModuleHandle(NULL), resrc);
fByte = LockResource(hPng);
lpstr = SHCreateMemStream(fByte, 200000);
GdipLoadImageFromStream(lpstr, &img);
*image = img;
}
void CreateBack(HWND hWnd)
{
HDC memDC = NULL;
HDC hdc = NULL;
RECT rect;
DeleteObject(curBack);
GetClientRect(hWnd, &rect);
hdc = GetDC(hWnd);
memDC = CreateCompatibleDC(hdc);
curBack = CreateCompatibleBitmap(hdc, rect.right, 44);
SelectObject(memDC, curBack);
/* gdiplus - background*/ {
int e = 0;
GpGraphics *g;
GdipCreateFromHDC(memDC, &g);
GdipDrawImageRectI(g, background, e, 0, 971, 44);
GdipDeleteGraphics(g);
}
DeleteObject(memDC);
ReleaseDC(hWnd, hdc);
}
Just a quick note: This GDI+ stuff is really CPU/memory intensive for a couple of reasons. Although fun I did abandoned this approach in favor of gdi and simple BMPs.

If you're loading the images from a resource file, then no, you can't use PNGs, you have to use ICOs. Fortunately, there are a number of tools that can convert PNGs into ICOs, including ImageMagick (great for automation), and MSPaint as a lowest common denominator.
If you're loading image files at runtime, then you can load any type of image format you want (e.g. use libpng for loading PNGs), but you still have to convert them to icons internally before you can do interesting things with them, such as setting them as a window's icon. Once you've decoded the image data, it's not terribly difficult to convert it to the proper format, but it's not trivial, it just involves a lot of data mangling and strange structs and function calls from the Win32 API.

Related

How can I make assets accessible to players for modding?

My game includes image files and json configuration files that I would like to make accessible in the deployed game's folder structure so that players can easily edit or swap them out.
I have considered/tried the following approaches:
My initial approach was to use the Resources folder and code
such as Resources.Load<TextAsset>("Rules.json"). Of course,
this did not work as the resources folder is compiled during builds.
I investigated the Addressables and AssetBundle features, but they do not seem aimed at solving this problem.
After asking around, I went for using .NET's own file methods, going
for code like File.ReadAllText(Application.dataPath + Rules.json). This seems like it will work, but such files are still not deployed automatically and would have to manually be copied over.
It seems that the StreamingAssets folder exists for this, since the manual advertises that its contents are copied verbatim on the target machine. I assume that its contents should be read as in the previous point, with non-Unity IO calls like File.ReadAllText(Application.streamingAssetsPath + Rules.json)?
So yeah, what is the 'canonical' approach for this? And with that approach, is it still possible to get the affected files as assets (e.g. something similar to Resources.Load<Sprite>(path)), or is it necessary to use .NET IO methods to read the files and then manually turn them into Unity objects?
After asking the same question on the Unity forums, I was advised to use the StreamingAssets folder and told that it is necessary to use .NET IO methods with it.
An example for how to load sprites as files using standard IO can be seen here: https://forum.unity.com/threads/generating-sprites-dynamically-from-png-or-jpeg-files-in-c.343735/
static public Sprite LoadSpriteFromFile(
string filename,
float PixelsPerUnit = 100.0f,
SpriteMeshType type = SpriteMeshType.FullRect)
{
// Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference
Texture2D SpriteTexture = LoadTexture(filename);
Sprite NewSprite = Sprite.Create(
SpriteTexture,
new Rect(0,
0,
SpriteTexture.width,
SpriteTexture.height),
new Vector2(0, 0),
PixelsPerUnit,
0,
type);
return NewSprite;
}
static private Texture2D LoadTexture(string FilePath)
{
// Load a PNG or JPG file from disk to a Texture2D
// Returns null if load fails
Texture2D Tex2D;
byte[] FileData;
if (File.Exists(FilePath))
{
FileData = File.ReadAllBytes(FilePath);
Tex2D = new Texture2D(2, 2);
// If the image is blurrier than what you get with a manual Unity import, try tweaking these two lines:
Tex2D.wrapMode = TextureWrapMode.Clamp;
Tex2d.filterMode = FilterMode.Bilinear;
// Load the imagedata into the texture (size is set automatically)
if (Tex2D.LoadImage(FileData))
{
return Tex2D; // If data = readable -> return texture
}
}
return null;
}

Storing images in windows phone 8

I have been really cracking my head trying to write and read png files into a folder in Windows Phone 8. From few blogs sites and codeplex i found that the there is an extension to the WritableBitmap Class which provides few extra functionalities. ImageTools has PNG encoder and decoder. But I really cant find examples to use them.
What Im trying to achieve here is to create a folder called page and then in it a file called Ink File. I want to convert the bitmap to a PNG and store it there. The bitmap is created from the strokes drawn on a canvas. The class ImageTools provides a function called ToImage to convert the strokes from the canvas to image.
For storing
ExtendedImage myImage = InkCanvas.ToImage();
var encoder = new PngEncoder();
var dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
StorageFile Ink_File = await dataFolder.CreateFileAsync("InkFile", CreationCollisionOption.ReplaceExisting);
using (var stream = await Ink_File.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
{
using (var s = await Ink_File.OpenStreamForWriteAsync())
{
encoder.Encode(myImage, s);
await s.FlushAsync();
s.Close();
}
}
Is this a correct method? I receive some null exceptions for this. How do i find if the image is saved as png. How is this image saved? Is it encoded and saved in a file or is it saved as a png itsef. And how do we read this back?
I have checked out this, this , this and lot more like this.
I'm developing app for WP8
I have used the PNG Writer Library found in ToolStack and it works :)

Perl module Image::Imlib2 trouble saving gifs

I'm using the perl module Image:Imlib2 to resize photos. Here is the code:
#create thumbnail
my $old = Image::Imlib2->load("$upload_dir/$name");
my $new = $old->create_scaled_image(80, 80);
$new->save("$upload_dir/$thumbnail_name");
This code works fine when I am saving a jpg or png file, but whenever I save a gif, I get an internal server error. Here is the error I get in my apache log file:
Image::Imlib2 save error: Unknown error at /path/to/script/script.pl
Any Ideas?
Thanks!
I don't think Imlib2 supports writing GIF files at all. From a rather old mailing list posting:
I discovered that Imlib2 has absolutely NO support for writing out gif files.
Furthermore, if you look at the source, you'll see a couple files of interest:
imlib2-1.4.5/src/modules/loaders/loader_png.c
imlib2-1.4.5/src/modules/loaders/loader_gif.c
Inside loader_png.c you'll find this:
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
/*...*/
}
char
save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
/*...*/
}
and inside loader_gif.c, you'll find:
char
load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
char immediate_load)
{
/* ... */
}
but no save implementation. So it looks like Imlib2 can read GIFs but can't write them and that's where your trouble lies.
I'd recommend that you switch to GraphicsMagick and Graphics::Magick. GraphicsMagick is a fork of ImageMagick that is faster and has fewer bugs, this is what Flickr uses internally so it should be good enough for you. GraphicsMagick unfortunately uses the somewhat strange ImageMagick API but you can hide the ugly details behind a wrapper without too much difficulty.
Alternatively, save all your thumbnails as JPEGs or PNGs.

iOS support for Canon RAW format?

I know the iPad can read Canon RAW (.CR2) files when used with the Camera Kit but is any of that file format reading accessible to an iOS developer? Or are we just limited to things supported in the UIImage Class Reference document?
(https://developer.apple.com/documentation/uikit/uiimage)
For something like this, Apple's image APIs are not going to be sufficient for what you need. However, there are a few third party APIs that should work with the iPhone. Libraw is a good one that I found that has a C interface. Since Objective-C is a strict superset of C, you will probably be able to use it in your iOS application.
From what I see in their docs, you might be able to write a CR2 image as a TIFF, then decode it as a UIImage like this:
NSString * cr2Path = #"path/to/cr2/file";
NSString * tiffPath = [NSTemporaryDirectory stringByAppendingPathComponent:#"x.tiff"];
libraw_data_t * cr2Data = libraw_init(0);
libraw_open_file(cr2Data, [cr2Path UTF8String]);
libraw_unpack(cr2Data);
// setup encoding params
cr2Data->params.output_tiff = 1;
cr2Data->params.use_camera_wb = 1;
// encode and write as tiff
libraw_dcraw_process(cr2Data);
libraw_dcraw_ppm_tiff_writer(cr2Data, [tiffPath UTF8String]);
libraw_recycle(cr2Data); // free the memory
// load the UIImage
UIImage * myImage = [[UIImage alloc] initWithContentsOfFile:tiffPath];
// use myImage here ...
[myImage release];
From what I have seen, it looks like you will be able to download it here and then add the src files from the src/, libraw/, dcraw/, and internal/ directories to your Xcode project. Hopefully you will not run into any weird linking/compiling issues.

ClearCanvas DICOM Library - How to use Overlay Planes?

NOTE:: This may be a better question to answer:: Free DICOM files, with Multiple Overlays
Hi, I have a question relating to tag DicomTags.OverlayData & Overlay Planes.
As of now I can get back overlay data from a DICOM file in ClearCanvas and uncompress & display it using:
var overlayData = dicomFile.DataSet[DicomTags.OverlayData];
I also use other tags in the DICOM file for Overlays such as, OverlayOrigin, OverlayColumns, OverlayRows etc...
So my question is, how do OverlayPlanes come into play here? All these Overlay tags seem to be global & not grouped in a OverlayPlane tag or something.
Is plane data layered in the OverlayData tag?? I'm new to DICOM & a little confused about this.
The ClearCanvas DICOM assembly has several helper IOD classes that make it a bit easier to access specific modules within a DICOM Message. The OverlayPlaneModuleIod class is one such IOD class that make it easier to access all of the tags together within an overlay plane. The following code shows an example of how to use this class to check and access an each of the potential overlay planes, without having to worry about the various tags involved:
DicomFile theFile = new DicomFile("filename.dcm");
theFile.Load();
OverlayPlaneModuleIod iod = new OverlayPlaneModuleIod(theFile.DataSet);
for (int i = 0; i &lt 16; i++)
{
if (iod.HasOverlayPlane(i))
{
OverlayPlane overlay = iod[i];
byte[] overlayData = overlay.OverlayData;
string description = overlay.OverlayDescription;
}
}
This link answered my question for the most part as I needed to just understand something about overlay grouping.
http://www.medicalconnections.co.uk/wiki/Number_of_Overlays_in_Image