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.
Related
I have a problem with WriteableImage conversion.
I create a WriteableImage to process its pixcel, then i want to create a BitmapImage with WriteableImage data, but not success... Some functions are not support for windows phone.
Any ideas, some one ?
BitmapImage is not a read-only version of a WriteableBitamp, as we would normally expect. (From the BitmapImage documentation: "The BitmapImage can be used to reference images in the JPEG and PNG file formats." http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.media.imaging.bitmapimage(v=vs.105).aspx)
So, probably the only way to make the "conversion" is to use WriteableBitmap.SaveJpeg to save on a memory stream and then load it to a BitmapImage via SetSource. This is not a good practice, so if possible I would use WritableBitmaps all the way and avoid conversion.
I am working with MediaLibrary on WP7 and I am doing steganography on BitmapImage (WriteableBitmap) which works fine (using this approach: http://www.codeproject.com/Articles/4877/Steganography-Hiding-messages-in-the-Noise-of-a-Pi)
Now the problem occurs when I call MediaLibrary.SavePicture method to save my bitmap to the phone. When I load this saved bitmap again from the phone, I can see that the pixels of the bitmap are shifted and my steganography data is lost.
Is there a way to avoid this behavior during the save method?
Better yet, is there a way to attach some metadata to my bitmaps that would be persisted with the bitmap?
Thanks a lot!
Leo
The issue might be caused by the fact that MediaLibrary.SavePicture saves the stream as a JPEG whereas your bytestream represents an uncompressed bitmap. Since JPEG is a lossy compression format, your data might be thrown away and so your hidden byte stream becomes corrupt. I'm not familiar with steganography but, if possible, you could try creating a blank JPEG image and writing your data to that. This way, your image format remains the same. You could try using Extensions.SaveJpeg with a quality value of 100, writing the data to that and then saving it to the MediaLibrary.
I am a bit confused about what the best approach is to resize a JPEG file on disk and save the resized JPEG as a new file to disk (on Mac OS X with Cocoa). There are a number of threads about resizing, but I am wondering what approach to use. Do I need to use Core Graphics for this or is this framework "too much" for a simple operation as a resize? Any pointers are welcome as I am a bit lost.
Core Graphics isn't “too much”; it's the right way to do it.
There is a Cocoa solution:
Create an image of the desired size (the destination image).
Lock focus on it.
Draw the source image into it.
Unlock focus on it.
Export it to desired file format.
Write that data somewhere.
But that destroys metadata.
The Core Graphics solution is not a whole lot different:
Use an image source to load the image and its metadata.
Create a bitmap context of the desired size with the source image's color space. (The hard part here is making sure that the destination context matches the source image as closely as possible while still being in one of the supported pixel formats.)
Draw the source image into it.
Capture the contents of the context.
Use an image destination to write the image and metadata to a file.
And the Core Graphics solution ensures that as little information as possible is lost along the way. (You may want to adjust the DPI metadata, if present.)
Install and use ImageMagick.
I want to save my created image as a PNG or JPEG file with the help of GDI+ but i can't find a way to do this. Seems that there is no way to create a non file based Image and fill it with a bitblit from the HBITMAP.
Or do i miss something?
Use the Bitmap::FromHBITMAP() method. Then just Save() it.
I'm trying to load some images using Bitmap.getBitmapResource(), but it takes about 2 or 3 seconds per image to load. I'm testing on the Storm, specifically. The odd thing is, when I install OS 5.0, the loading goes in a snap, no delay at all.
Should I be looking at the format used? Or where the files are stored? I've tried both 24- and 8-bit PNGs, with transparency. The files are stored in a subdirectory in the COD, so getBitmapResource is passed a path, like "images/img1.png" instead of just "img1.png".
Is any of this making things slower?
If you're looking for the most efficient format for storing image data within your application binary, the recommendation is PNG with the 565 colorspace. The BlackBerry Theme Studio toolkit has the ability to load any PNG and export it in this format. Its the best one because its what the BlackBerry uses internally.
Try to use EncodedImage, see Is it better to use Bitmap or EncodedImage in BlackBerry?
In case you need Bitmap class, try also bmp (don't forget to turn off "convert image files to .png" option in BB project settings)