Hi all i want to display video thumbnail with rectangle shape as in given link .I have used some code and now video is displaying in thumbnail but not with rectangle as display in given link.So please suggest me, is this is possible in android or not .If possible then how..Thanks..
http://lh3.ggpht.com/_xBHTh_QdoYY/S81nyg57zsI/AAAAAAAAA2A/knYE08lHypU/video3e312550f115%5B15%5D.jpg
Use this code to get the thumbnails-
Bitmap _bitmap = null;
thumbnail = new ImageView(mContext);
thumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);
try {
String path = "SOME PATH GOES HERE...";
_bitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MICRO_KIND);
thumbnail.setImageBitmap(_bitmap);
} catch (Exception e) {
thumbnail.setBackgroundResource(R.drawable.icon);
e.printStackTrace();
};
Related
I'm using this method for loading albumArt in list
long thisAlbum = musicCursor.getLong(albumColumn);
Bitmap artWork = null;
Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, thisAlbum);
try {
artWork = MediaStore.Images.Media.getBitmap(
musicResolver, albumArtUri);
artWork = Bitmap.createScaledBitmap(artWork, 150, 150, true);
} catch (FileNotFoundException exception) {
exception.printStackTrace();
artWork = BitmapFactory.decodeResource(getResources(),
R.drawable.no_cover);
} catch (IOException e) {
e.printStackTrace();
}
songsList.add(new Songs(thisId, thisTitle, thisArtist, artWork));
}
everything is working fine but when i open my activity it takes more then 10 seconds to load the activity and when i remove this bunch of code activity open as normally ,can anyone tell me please why it is happening and please tell me also what to do or any update for code
Instead of Bitmap I always use glide library(It gives smoothness to app)
So just add it in build.gradle(Module App)
compile 'com.github.bumptech.glide:glide:3.7.0
code to load image in imageview using glide
Glide.with(context).load(imagePath).crossFade().diskCacheStrategy(DiskCacheStrategy.ALL).thumbnail(0.5f).into(imageView);
I Hope It will Help You :)
You are trying to make the bitmap from the images from your phone.
I think the images in your phone are too large.
You can use Glide to make Bitmap for your local image.
Glide.with(mContext)
.load(new File(pictureUri.getPath())) // Uri of the picture
.asBitmap().
into(100, 100). // Width and height
get();
Remember to run this code within AsyncTask or Thread.
Hope it will helpfull to you.
I am developing a module for which i want to show all the user's videos from sd card into a Gridview. I have grabbed video file paths in usual way (Checking if file or directory and save if its a file) in a arraylist and grabbed its bitmap thumbnail with following code:
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(VideoValues.get(position).getAbsolutePath(),
Thumbnails.MINI_KIND);
Obviously this code runs in a background thread. But the only problem is that the gribview still freezes a lot while scrolling. According to me the main problem is extracting the bitmap from video, which takes a lot of time. Can anyone suggest me a different way to get bitmap from video and how it in a grid ? I have seen the smooth behavior in other apps like Facebook, etc. But I cannot figure out as to how that can be done.
please use below method for retrive video thumbnail from video
#SuppressLint("NewApi")
public static Bitmap retriveVideoFrameFromVideo(String videoPath)
throws Throwable
{
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
}
catch (Exception e)
{
throw new Throwable(
"Exception in retriveVideoFrameFromVideo(String videoPath)"
+ e.getMessage());
}
finally
{
if (mediaMetadataRetriever != null)
{
mediaMetadataRetriever.release();
}
}
return bitmap;
}
Am trying to download an image using jsoup library and set it to image view but the downloaded image is cropped automatically. i don't know if it is the library or something else. Here is my code, Any one to help me please?
try {
// Connect to the web site
Document documentImage1 = Jsoup.connect(url).get();
// Using Elements to get the class data
Element img = documentImage1.select("div[class=media-img imgflare--river] img[src]").first();
// Locate the src attribute
String imgSrcImage1 = img.attr("src");
// Download image from URL
InputStream inputImage1 = new java.net.URL(imgSrcImage1).openStream();
// Decode Bitmap
image1 = BitmapFactory.decodeStream(inputImage1);
} catch (IOException e) {
e.printStackTrace();
}
I am downloading a bitmap from a website and then displaying it in my application. Whenever I download this image and set it into an ImageView, there is always a lot of extra space above or below the actual image. This extra space is part of the ImageView and is only there after I set the ImageBitmap to the downloaded bitmap.
So, this is making me think that the extra space is somehow part of the bitmap.
However, when I download the same image in a Webview, there is no extra space.
If you have any ideas on why this could be happening, please let me know! Let me know if you need any more information, thanks.
Edit: Here's my code getting the bitmap:
InputStream in = null;
Message msg = Message.obtain();
msg.what = 1;
try{
in = openHttpConnection(_url);
if (in != null)
{
Bitmap bit = BitmapFactory.decodeStream(in);
Bundle b = new Bundle();
b.putParcelable("bitmap", bit);
msg.setData(b);
in.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
_handle.sendMessage(msg);
And this is what I use to then for the ImageView, I get the bitmap from the code above and:
imageV.setImageBitmap(comic);
Edit 2:
After trying this with some other images from different website, I've found that this white space is not always there. Given that, and there's probably not anything wrong with the code, are there any suggestions on removing this extra space since it doesn't show up in the actual image online nor in a webview?
imageSize = din.readInt();
imageName = din.readUTF();
byte b[] = new byte[imageSize];
din.readFully(b);
bmImg = BitmapFactory.decodeByteArray(b,0,b.length);
//This works for me....
//din is DataInputStream object.
I'm parsing the image from the url, i want to display the corner of parsed image as roundrect(similar to figure2) but i'm not able to do that, can anyone guide me regarding on this, My code for parsing the image from url is
img_value = new URL(VAL4[arg0]);
Log.v("Image_Url1",img_value.toString());
try{
mIcon11 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
img.setImageBitmap(mIcon11);
}catch(Exception e)
{
Log.v(TAG,"error "+e);
}
Figure 2
Figure1
Give this URL a try: Draw circular region over bitmap
In essence what you want to do is clip the original bitmap by applying a path to the canvas in which you draw.