how to display a gif image in windows phone 7? - windows-phone-7

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

Related

Creating thumbnail images for social network site using Laravel

I'm wondering if anyone knows a good strategy for solving this problem:
I'm creating a social networking site using Laravel 4. Users can upload pictures to their own gallery. These pictures can be any shape and size but the gallery on their profile will only display a cropped and resized thumbnail of the image (200px x 200px), which you can click on to view the full image.
Im using the Laravel plugin Intervention right now, which saves the original image, then resizes and crops that image and saves it again ( so now I have 2 copies). I then display the cropped/resized image as the thumbnail that links to the full size original image. However, I find that making copies of every image will be a tedious waste of space on my server since there could be thousands of images uploaded to the site.
Is there a way to grab the original image, resize and crop it on the fly and display it only when the user loads the page without having to save the thumbnail to the server? or am I stuck with having to make a cropped copy for every image?
A great example that shows what I'm looking to achieve is the way Facebook crops pictures into squares in a users picture gallery or how they are cropped and resized on the newsfeed when a user uploads multiple images to a status.
Any advice is greatly appreciated!
Have you seen League/Glide yet? It's basically a wrapper for Intervention/Image and Intervention/ImageCache. Glide's Laravel setup video gets you set up in two minutes (pay attention to the second example).
Yes Intervention let's you manipulate and display on the fly too.
Here's a simple example (obviously you would actually do it with a controller etc)
Route::get('img/profile/picture.jpg', function(){
$img = Image::make('path/to/profile/picture.jpg');
// resize, crop, whatever
return $img->response();
});
And then you just set the right URI to this route as src of your image.
Intervention Docs
Keep in mind that this will use more server resources and make the image response take longer

How to add a thumbnail Image for an encrypted image?

I Encrypted an image by using AES algorithm. Encryption and Decryption works well. Now the thumbnail of the image is the default image.
But I want something that looks useful for the user. like this image.
I have searched a lot but I can find only the quicklook for the document based applications. How can I add thumbnail for jpeg, png or tiff images ?
I assume you know the path to the file when you create it and you have the icon images in your project, so then just use the NSWorkspace method setIcon:forFile:options:.

Windows Phone 8, how to convert an image to .png?

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/

How to build a 8.5 x 11 inch "Poster" PNG or JPG from Text and Pics

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.

Can jpg images support animation?

jpeg image
How is the above jpg image animated? As far as I know jpg format does not support animation.
No, the JPEG file format has no inherent support for animation.
The image you linked is actually an animated GIF disguised with a jpg file extension. (The browser apparently ignores even the MIME type and looks at the file header bytes in such cases.)
If you view the image in firefox, you can right-click on it and select properties:
You'll see Type: GIF image (animated, 54 frames)
Thus, it is a gif-image that has been renamed to .jpg.
For completeness, I'd like to point our that there's Motion-JPEG - sort of a jpg animation.
MJPEGs, usually produced by webcams, are a stream of JPEG files concatenated together, one after another, sometimes delimited by a HTTP header, and served by webcam-webservers with a MIME-Type of multipart/x-mixed-replace;boundary=, where boundary= defines the delimiter.
A search for animated JPEG related projects on github results in two findings:
In case people care about the size of an animated GIF, they strip it into separate JPG frames and tell the browser to exchange these frames in-place via some JavaScript code. For example. (Pawel's answer)
Then there's actually a proposed Animated JPEG standard, which stems from MJPEG and declares framerate and so forth in each JPG frame. Not probable to arrive in browsers anytime soon.
And lastly, I've seen image-hosters to replace large animated GIFs with a mp4 version of the GIF for presentation, plus some Javascript to serve the actual GIF for downloads/non-supported browsers.
And no, JPEG itself, via JFIF, does not offer a facility to animate a JPG file in itself, just as Noldorin already noted in the chosen answer. :shrug:
It is a GIF image... the extension has been changed by hand. Browser engine is smart enough to determine image format regardless of file extension.
var c = 1;
/* Preloading images */
var image1 = new Image();
image1.src = "a1.jpg";
var image2 = new Image();
image2.src = "a2.jpg";
var image3 = new Image();
image3.src = "a3.jpg";
var image4 = new Image();
image4.src = "a4.jpg";
var image5 = new Image();
image5.src = "a5.jpg";
function disp_img(w)
{
if (c == 6)
{
c = 1;
}
var img_src = "a" + c + ".jpg";
document.ani.src = img_src;
c++;
}
t = setInterval("disp_img(c)", 1000);
No JPEG doesn't support animation. Saving a GIF file with .jpeg extension doesn't male it a JPEG file. It's still a GIF file. Because OS Image viewer doesn't look into file extension it rather looks into the content.
If you open that file as binary (in a text editor) you will see the first line contains
GIF89ad�d�˜|� Which is the magic number for GIF.
Yes,
you can make animation using single jpeg. Google "jpeg css sprites". Of course this will not be native animation support by jpeg format.
A bit of a necro-post but since this question popped first when I tried to get info about pixel motion jpeg, here's some additional info.
Since Pixel2, Google created motion jpeg, which is an ordinary jpeg at the end of which there's an mp4 video.
More on this here:
https://android.jlelse.eu/working-with-motion-photos-da0aa49b50c
JPG does not animate. You either saw a series of JPG images rendered with javascript or you saw a GIF file named as a JPG. A web server and browser might still recognize the correct GIF filetype, even if the wrong extension has been added to the filename.
If you open the image file and if it is a sort of GIF format by using a hex editor, you see the following 4 bytes designating that image type is of GIF.

Resources