For Windows Phone 8 (and I'm assuming it will be similar for Windows 8), how does one convert any image they get to .png?
For example, I get a .jpeg or .gif and I convert it to .png.
Would also be interested in maybe turning a .png to .jpeg.
I would prefer built in methods before third party applications.
Thank you!
There are no built-in features in WP7/WP8 to convert from JPG to PNG.
One good 3rd party framework to use if all you need is to save WriteableBitmap as JPEG is ToolStack C# PNG Writer Library.
var myBitmap = new WriteableBitmap(tempBitmap);
// Create the destitnation stream.
var pngDest = new System.IO.IsolatedStorage.IsolatedStorageFileStream("test.png", FileMode.Create, isoStore);
// use the WriteableBitmap extension to write out the PNG
myBitmap.WritePNG(pngDest);
If you need a more fully featured toolset (such as loading JPG) check out WriteableBitmapEx and this great article by Rene Schulte # Convert, Encode And Decode Silverlight WriteableBitmap Data
One thing to consider is to use a program outside your app to convert your images.
I use paint or gimp. You can download gimp for free and it is a good program.
Here is a place to start:
http://www.gimp.org/
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 trying to load images from facebook. if a user has set a profile picture, then the picture is a jpg, however, if a user has not set one, then the picture is a stub image in gif format. i know that wp7 does not support displaying gif images (out of the box). is there any way to detect if the final picture is a gif or not?
for example, i make a BitmapImage like this:
BitmapImage img = new BitmapImage(new Uri("https://graph.facebook.com/userid1/picture"))
for this uri, the user does not have a profile picture. so i get taken to a stub gif image at https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif.
if a user does have an image, then i request it as follows.
BitmapImage img = new BitmapImage(new Uri("https://graph.facebook.com/userid2/picture"))
for the above url i get taken to a url like this: https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/000000_1621037713_00000000_q.jpg
my question is then, once i get the BitmapImage object, img, can i determine if this is a JPG or GIF? can i convert it to a JPG if it is a gif?
i looked at some related questions, but the API discussed loaded the image asynchronously, which is not what i wanted at the moment. furthermore, there was poor documentation.
any help is appreciated.
nevermind, i followed the instructions here: Display GIF in a WP7 application with Silverlight. the user gave an excellent walk through.
what you need to do before you do what this user suggested is to download the source code from codeplex.
then you need to download BitMiracle's JPEG library from http://bitmiracle.com/libjpeg/.
go ahead and go into the /src/ImageTools directory and open up ImageTools.Phone.sln. add the ImageTools.IO.Jpeg.Phone project to the solution.
when you build the solution it will complain about not finding BitMiracle's JPEG dll, go ahead and reference that DLL for the Jpeg project. build again, and it should work.
First download the image(any) using Httprequest or Webclient and then convert to jpg or png from gif(if it is gif) in the following way.
GifDecoder gd = new GifDecoder();
ImageTools.ExtendedImage img = new ImageTools.ExtendedImage();
gd.Decode(img, stream); //stream means image stream
PngEncoder png = new PngEncoder();
png.Encode(img, isoFileStreamdownload); //isoFileStreamdownload means stream, which is used to save image in image file like(image.png))
using ImageTools.dll, ImageTools.IO.Gif.dll,ImageTools.IO.Png.dll (Images Tools)
I think it helps to you
I need to build a Poster (8 1/2 by 11) using data entered by the user and pictures and place that poster in the user's media library. It looks like BitmapImage is the mechanism to build either a JPG or PNG image but how do I place text strings and pictures on the image in a grid/form fashion?
TIA,
George
If you need to place things in a grid ina form-style, it might be worth building it up in XAML or in code and then using WriteableBitmap to render it to a bitmap.
You might find the following posts useful to achieve this:
WP7 Screen Capture On-Device
Screen Capture on Windows Phone 7
For an example of combining images and text see how do i add text to image in c# or vb.net
Of course, any image can be printed at any size, it depends on the quality you want.
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)
I have a need to select a portion of a .png file, with specific cordinators, and delete this area then save the file back with the same name.
I would appreciate if you can help to come up with a VBScript script that can accomplish this task.
It would be great if all proesses happen in the background, but it would be ok too if the image file has to be open and visible. Thanks a bunch!!!
A PNG file, like any other binary file can be edited with CMD or VBS.
A PNG file layout is as follows:
File header
"Chunks" within the file
Pixel format
Transparency of image
Compression
Interlacing
Animation
Read the PNG format in RFC 2083 to know how to edit/create a PNG file at binary/bit level.
To speed up the editing process, libraries are available for application level editing.
Here are some VBA codes for image manipulation.
ImageMagick also provides libraries that can be accessed via VBS for image editing.
Here's a VBScript Image Class for bmp and pcx files (which PNG can be converted to before editing via WIA).
Loadpicture function described here doesn't seem to support PNG, but this discussion might solve it.
The Windows Image Acquisition Library v2.0 supports PNG, BMP, JPG, GIF and TIFF image formats, and comes with Windows Vista and later versions. Sample scripts are available to demonstrate "image manipulation using the ImageFile object". The Vector.ImageFile property also "creates an ImageFile object from raw ARGB data".
More sample codes here & here show how to rotate, flip, scale, crop, etc with WIA Image constants in vbs. To remove unwanted areas of image (with given coordinates), use the crop function.
Here's a discussion of WIA 2.0 image editing on stackoverflow.
VBScript doesn't have any image editing functions, so you need an external tool for that. For example, GIMP can do image processing from the command line (see here). ImageMagick provides a scriptable component in addition to the command-line interface (details here).
To run a command line from a VBScript script, you can use the WShShell.Run method. To create an instance of a COM scriptable component, use the CreateObject function.