How to apply round rectuangular shape to the parsed image from android? - android

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.

Related

Android make preview from images on web

I'm trying to make preview as Thumbnail from images on web before downloading, it means i have more item on RecyclerView and i'm trying to view simple blurred preview from images but i dont know whats solution, i use this below code but i think this code download full image, like with social application such as whatsApp or Telegram how can i make preview image on web and show that to users?
new Thread(new Runnable() {
#Override
public void run() {
//First create a new URL object
URL url = null;
try {
if (checkNetWorkConnection()) {
url = new URL("http://wallpaperwarrior.com/wp-content/uploads/2016/09/Wallpaper-2.jpeg");
//Next create a file, the example below will save to the SDCARD using JPEG format
File file = new File(APP.DIR_APP + APP.IMAGE + "/" + "Wallpaper-2.jpg");
//Next create a Bitmap object and download the image to bitmap
Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
//Finally compress the bitmap, saving to the file previously created
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, new FileOutputStream(file));
}
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("Error ", e.getMessage());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("Error ", e.getMessage());
} catch (IOException e) {
e.printStackTrace();
Log.e("Error ", e.getMessage());
}
}
}).start();
You can use picasso lib.
Picasso
.with(context)
.load("http://wallpaperwarrior.com/wp-content/uploads/2016/09/Wallpaper-2.jpeg")
.resize(600, 200)
.centerInside()
.into(imageViewResizeCenterInside);
You can give circle shape to image using Transformation api of picasso.
refer this Picasso
You can try implement with this zoom effect. It is being use by many application. With the example you can create your own background like full screen black background but you need to implement it yourself which is pretty simple but kinda lot of work to do.
Beside why not try to use Glide or Picasso to download and display the image? It help you save a lot work such as caching, download in asyncs,resize etc.
When you work with image especially with recycleview or listview there is some problem you need to always remember. Every time you scroll the listView/RecycleView it actually re-download the image so you have to really check wether it already exist in your sdcard to avoid this problem beside there is better to cache is memory although you already save it on sd card but still you can avoid memory crash by cache it in memory. Those hard work done by using either one of the library I just show you.

Save RelativeLayout with content as an image

I have relativelayout (A template) where it contain textboxes whose content is populated at runtime.On clicking save button,I need to save the template as an image in SD card.Is it possible.
I referred the below link:
How do I convert a RelativeLayout with an Imageview and TextView to a PNG image?
But the image saved cannot be opened.
Is my requiremnet possible.Or else please advice how can I achieve it.
I am behind this for several days.I am new to ANdroid.Please help.
Thanks in Advance.
You can pass any view or layout to devBitmapFrmViewFnc function and get the bitmap. You can save the bitmap in jpeg using devImjFylFnc.
|==| Dev Bitmap Image from View :
Bitmap devBitmapFrmViewFnc(View viewVar)
{
viewVar.setDrawingCacheEnabled(true);
viewVar.buildDrawingCache();
return viewVar.getDrawingCache();
}
|==| Create a JPG File from Bitmap :
static void devImjFylFnc(String MobUrlVar, Bitmap BitmapVar)
{
try
{
FileOutputStream FylVar = new FileOutputStream(MobUrlVar);
BitmapVar.compress(Bitmap.CompressFormat.JPEG, 100, FylVar);
FylVar.close();
}
catch (Exception ErrVar) { ErrVar.printStackTrace(); }
}

Image is cropped when using jsoup library

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();
}

How to display rectangle thumbnails for video in android

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();
};

Extra space above and below Android Bitmap

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.

Categories

Resources