I wonder how to display image if I have a Bitmap and don't want to give as a parameter URL to image using Universal ImageLoader library.
Bitmap img = getDefaultBitmap();
ImageLoader.getInstance().displayImage(img); // I need something like this (for example with parameters to display image like width and height)
Firstly,
you have to save bitmap and then u can pass that path to show that bitmap into imageview using imageloader.
//-- Saving file
String filename = "pippo.jpg";
File sd = Environment.getExternalStorageDirectory();
File dest = new File(sd, filename);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
try {
FileOutputStream out = new FileOutputStream(dest);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
//-- show bitmap to imageview
imageLoader.displayImage(dest.getAbsolutePath(), imageView);
Related
This is my code inside onActivityResult. PathUtil class is getting full file path from Uri. I am picking single picture from Gallery :)
try {
selectedFilePath = PathUtil.getPath(SmoothPhotoActivity.this, selectedImageUri);
File sd = Environment.getExternalStorageDirectory();
File image = new File(selectedFilePath);
String filePath = image.getPath();
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
Bitmap outputImage = imageFilter.processFilter(bitmap);
ivPhotoSelected.setImageBitmap(outputImage);
} catch (URISyntaxException e) {
e.printStackTrace();
}
The following is my code. I'm trying to get a bitmap I create into the files folder so I can display it in a gallery. Any clue as a better way of/location to doing this or where my program is running into problems?
try{
BitmapDrawable drawable = (BitmapDrawable) mimageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
File directory = new File("data/data/com.example.feedme/files");
if (!directory.exists()){
directory.mkdirs();
}
FileOutputStream fileOutputStream = Record.this.openFileOutput(directory.toString(), Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.close();
} catch (Exception e){
Log.w("BitMapError", "Bitmap was not saved right");
}
I'm trying to create a bitmap that takes a "screenshot" of a view but who's bigger than the screen size, I need a bitmap of 1500px x 2115px to turn it into a pdf after that, but on phone is too big.
Here is my code which works if I use it with a tablet but not with the phone :
public void layoutToImage(View view, String imageName) {
view.setDrawingCacheEnabled(true);
view.measure(View.MeasureSpec.makeMeasureSpec(1500, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(2115, View.MeasureSpec.EXACTLY));
view.layout(0, 0, 1500, 2115);
view.buildDrawingCache(false);
Bitmap bm = view.getDrawingCache();
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File mFileImg = new File(Environment.getExternalStorageDirectory() + File.separator + imageName);
try {
mFileImg.createNewFile();
FileOutputStream fo = new FileOutputStream(mFileImg);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
}
Is this possible to achieve the same result on the tablet as on the phone? Any solution or suggestion will be helpful,
thank you.
How to capture shadow or elevation of views in the layout of the activity in a screenshots.This code take a screenshot for the view but it's not showing the shadow of the viewsenter image description here
View screenView = parentMain;
screenView.buildDrawingCache();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getWidth() , screenView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
screenView.layout(0, 0, screenView.getLayoutParams().width, screenView.getLayoutParams().height);
screenView.draw(c);
screenView.setDrawingCacheEnabled(false);
fakeImgView.setImageBitmap(bitmap);
Even if we add the harware acceleration at activity level it does not provides any effect.
Appreciate any alternative approaches
the result
Try this.
CardView card = (CardView) findViewById(R.id.card);
Now just pass the card to captureScreenShot(). It returns the bitmap and save that bitmap saveImage().
You can pass any view Like RelativeLayout, LinearLayout etc any view can pass to captureScreenShot().
// Function which capture Screenshot
public Bitmap captureScreenShot(View view) {
/*
* Creating a Bitmap of view with ARGB_4444.
* */
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bitmap);
Drawable backgroundDrawable = view.getBackground();
if (backgroundDrawable != null) {
backgroundDrawable.draw(canvas);
} else {
canvas.drawColor(Color.parseColor("#80000000"));
}
view.draw(canvas);
return bitmap;
}
// Function which Save image.
private void saveImage(Bitmap bitmap) {
File file = // Your Storage directory name + your filename
if (file == null) {
return;
}
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Finally call this function like this.
saveImage(captureScreenShot(card));
Now set Your Image like this.
File file = new File(“yourImageFilePath”);
if(file.exists())
{
yourImageView.setImageURI(Uri.fromFile(file));
}
Note : If setImageURI() not working then you can use below code.
File file = new File(“yourImageFilePath”);
if(file.exists())
{
Bitmap bitmap = BitmapFactory.decodeFile(file.toString());
yourImageView.setImageBitmap(bitmap);
}
How to copy image in Clipboard from drawable folder in android ?
I mean copy image from drawable folder in Clipboard and paste anywhere.
Plese Help me.....
if you want to copy the drawable image to sdcard you the below code.
You can do something like this,
if (isSdPresent()) { // to check is sdcard mounted
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bbicon = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
String extStorageDirectory = Environment.getExternalStorageDirectory()+ File.separator + "FolderName";
File wallpaperDirectory = new File(extStorageDirectory);
wallpaperDirectory.mkdirs();
OutputStream outStream = null;
File file = new File(wallpaperDirectory,"icon.png");
//to get resource name getResources().getResourceEntryName(R.drawable.icon);
try {
outStream = new FileOutputStream(file);
bbicon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
to check SDCard
public boolean isSdPresent() {
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}
You cannot do it. Simply because Android clipboard doesn't support this link.
The only things that you can keep in clipboard are: text, uri and intent.