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.
Related
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/
I am working on a windows Phone app that can read Album arts dynamically from Music files through MediaPlayer APIs. I wish to get album arts and resize for view's background. Since the resize would lose details and make image ugly so I would like to blur it or some kind of effect. Is there any API that I can blur the image? (either from C# or XAML)? Thanks a lot!
I would start by using WriteableBitmap instead, to get a WriteableBitmap from a BitmapImage you can do the following:
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
Then I would recommend using the WriteableBitmapExtension library. It has support for resizing the image:
wb.Resize(newWidth, newHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
To do the gaussian blur with WritableBitmapExtensions do the following (for some reason concolution doesn't edit the writableBitmap, so you have to assign it again to the same writableBitmap to see the result):
wb = wb.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5);
or
wb = wb.Convolute(WriteableBitmapExtensions.KernelGaussianBlur3x3);
(Just different weights for the neighbouring pixels).
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'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'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.