How to make simple image to animated image like GIF? - android

I wont to make simple image to Animated image like GIF.I can select the image for gallery and store in image file.But, How i can modify image file to animated image or GIF File .

you have to select images you want to make GIF, then use bitmaps and run code in background Thread/Asynchtask:
Here i used Drawable, in your case convert images into bitmap and use it.
Bitmap one=BitmapFactory.decodeResource(getResources(),R.drawable.neon0);
Bitmap two=BitmapFactory.decodeResource(getResources(),R.drawable.neon1);
Bitmap three=BitmapFactory.decodeResource(getResources(),R.drawable.neon2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
encoder.addFrame(one);
encoder.addFrame(two);
encoder.addFrame(three);
encoder.finish();
FileOutputStream outStream;
try{
outStream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() +
"/IMAGES_GIF/" + "animated.gif");
outStream.write(bos.toByteArray());
outStream.close();
}catch(Exception e){
e.printStackTrace();
}
Get Class from:
https://gist.githubusercontent.com/wasabeef/8785346/raw/53a15d99062a382690275ef5666174139b32edb5/AnimatedGifEncoder.java

This question needs a lot more information. Is the file already a GIF and it is not animating or are you trying to convert an image to a GIF? The latter is not possible, a GIF is a series of images.
You must create the GIF elsewhere and it is easiest to use a library like Glide (https://github.com/bumptech/glide) or Picasso (http://square.github.io/picasso/) to load the GIF.

Related

How to save images in .thumbnail folder with proper format?

I need to download images from server and store as thumbnails directly.
and for display images also i need to use images from .thumbnails folder directly. i am not getting how to create and save images as .thumbnail . and how to use images from that .thumbnail file.i searched online but everywhere only this below code present.
Bitmap thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), width, height);
any help?
Please check below code which helps you.
Follow below steps:
Calculate the maximum possible inSampleSize that still yields an image larger than your target.
Load the image using BitmapFactory.decodeFile(file, options), passing inSampleSize as an option.
Resize to the desired dimensions using Bitmap.createScaledBitmap().
Now you have your bitmap ready and you can save it any where using the following code
Bitmap thumbnail;
File thumbnailFile = ...;
FileOutputStream fos = new FileOutputStream(thumbnailFile);
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
hope it helps you and save your time.
Or use Glide library which store image as a full image and 1 thmbnail image which is power caching library which loads image quickly and once download image after load image from cache not from network.
Below is a Glide link please read it advantages and features and after used into your applications.
https://github.com/bumptech/glide

How to change android code from compress bitmap to reszie or scaled bitmap?

I try to change this code into resized or scaled bitmap cause if I use compress bitmap, it will get too small image. How can I change it?
FixBitmap3.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream3);
byteArray3 = byteArrayOutputStream3.toByteArray();
ConvertImage3 = Base64.encodeToString(byteArray3, Base64.DEFAULT);
NoLg3 = getIntent().getStringExtra("no_lg");
AsyncTaskUploadClass AsyncTaskUploadClassOBJ = new AsyncTaskUploadClass();
AsyncTaskUploadClassOBJ.execute();
There's a plugin called Android Drawable Importer that is essential. You can google it and download it. It does the heavy lifting for you with respect to resizing images.

in-memory and saved to file bitmaps are different for same byte[]

I have a byte array. I then create a Bitmap object from it like this and display it in an ImageView:
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
image.copyPixelsFromBuffer(buffer);
...
ImageView imgView = (ImageView) findViewById(R.id.image);
imgView.setImageBitmap(image);
I then create a file and store this byte array as an image
FileOutputStream fOut = new FileOutputStream(file);
image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
When I open this file in Gallery, it looks different than the one in the ImageView. I tried to write the bytes directly to file, as opposed to the Bitmap, but then I was not able to open the image at all.
ImageView:
Gallery:
I thought that Bitmap.CompressFormat.PNG, endured no compression. What am I missing here?
EDIT:
I don't know if it matters, but the original bytes array comes from encrypting another byte array that came from an original picture. I loaded an image from disk, created a byte array, modified it, and then tried the above with it.
It's probably because you view your image with different background colors in your app and in Gallery. Since you use Bitmap.Config.ARGB_8888 and effectively feed it random data, some pixels will be transparent in the resulting image, and the color of the background will "shine through" when you view the image. If you make the background color of your app black, the image will probably look like it does in Gallery.

change default "picture no available" icon in Android

I've wrote an app that encrypt/decrypt pictures. When the encrypted image is stored, in the image gallery we can see the "picture no available" icon for this encrypted image. I would like to change this to default icon, but I don't know where is this default stored...
thanks!
EDIT
What I am trying to do now, is with BitMapFactory convert the encripted file to a bitmap. The icon it's not possible to change and EXIF algorithm is not exactly what I want.
With this code I obtain a black bitmap, what I would like to do is to obtain a bitmap from the encripted file that shows colour pixels. Any idea?
Bittmap bitmap=BitmapFactory.decodeFile("/sdcard/abc.jpg");
Bitmap bm = bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 30, bos);
bos.toByteArray();
FileOutputStream ft = new FileOutputStream(new File("/sdcard/ab.jpg"));
bos.writeTo(ft);
bos.flush();
ft.flush();
bos.close();
ft.close();
Since your app encrypts images I guess that you want them all to be viewable only by your app. So why don't you just change the file extension to something other so that the Android Image gallery won't recognize the file as image and try to display it.
This is outside of your control. Default Gallery appliaction (and probably 1000 others on Google Play) display their own image when parsing fails the way they want.

What is wrong with saving image into sqlite database?

I want to write an image into database as blob type. But when i load this image from database, it's different from source image. I write source image into database as follow:
ByteArrayOutputStream bs = new ByteArrayOutputStream();
Bitmap medBmp = BitmapFactory.decodeStream(this.getResources().openRawResource(R.drawable.source_image));
medBmp.compress(Bitmap.CompressFormat.JPEG, 100, bs);
initialValues.put(IMAGE_COL,bs.toByteArray());
And here are images
source image:
Image is loaded from database
The background of source image is transparent, but the image is loaded from db has background in black.why are they different?What is wrong with my code?
Please help me out, thanks you so much.
You are saving the image as JPEG, and JPEG's don't support transparency. So, you would get that black background. Try using PNG format.

Categories

Resources