How to set bitmap size that fill parent? - android

I want to creat a bit map in the size that fill parent of the app window. how can i do that?
Bitmap maskImage = BitmapFactory.decodeResource(getResources(), R.drawable.img);
ImageView on = (ImageView) findViewById(R.id.on);
Bitmap result = Bitmap.createBitmap(maskImage.getWidth(), maskImage.getHeight(), Bitmap.Config.ARGB_8888);
on.setImageBitmap(result);

Only a single additional line is needed:
Once you have your ImageView:
ImageView on = (ImageView) findViewById(R.id.on);
on.setImageBitmap( . . . );
on.setScaleType(ScaleType.FIT_XY);
ScaleTypes are options for scaling the bounds of your image. You can read more about ScaleTypes in the official docs.

Related

How to disable anti-aliasing when scaling up an imageview in android?

I have a pixel art that I want to scale up. The problem is when I scale it up, it gets all blurred cause of the antialiasing. Is there a way to disable antialiasing directly from xml?
i hope its useful
Bitmap bmpSource = BitmapFactory.decodeResource(getResources(), SourceFileId);
//100 is dimension to resizing image size
//Passing filter = false will result in a blocky, pixellated image.
//Passing filter = true will give you smoother edges
Bitmap bmpScaled = Bitmap.createScaledBitmap(bmpSource, 100, 100, false);
ImageView img = (ImageView) findViewById(Your imageView Control Id);
img.setImageBitmap(bmpScaled);
is this what u want!?

Getting ColorMode from a ImageView Bitmap

Looking at this example, Im trying to determine of the image in view is of CMYK colormode or not. If it it, I it must not try to display it, and continue with the next image in my list
This is how I am setting up my ImageView
options.inSampleSize = calculateInSampleSize(options, imageWidth, imageWidth);
imageView = (ImageView)findViewById(R.id.imageView);
Bitmap image = decodeSampledBitmapFromResource(path, 1280, 700);
imageView.setImageBitmap(image);
imageView.setVisibility(View.VISIBLE);
How do I determine if this image is CMYK ? Or simply said, I do I determine if this image can be displayed or not

dynamically load imageView

I have a layout where one imageView want dynamically load an image from drawable files. I want this I have a certain size imageView whatever drawable image, so you need to assign a size to upload. I searched the android developers but I've only seen functions to set the maximum height and width, but ir doesn't works.
I put the code:
image = getIntent().getExtras().getString("image");
ImageView paper = (ImageView)findViewById(R.id.imageView1);
Resources res = getResources();
int id = getResources().getIdentifier(image, "drawable", getPackageName());
Drawable drawable = res.getDrawable(id);
paper.setImageDrawable(drawable);
Can you help please?
thank you very much
You can use
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);
and retrieve it on the other end:
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
// bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
bitmap = Bitmap.createScaledBitmap(bitmap, 250, 250, true);
img.setImageBitmap(bitmap);

How to set width of ImageButton when setting the background image larger in android?

I want to programmatiacally set the larger Image as background of ImageButton in Android and set its height and width as fixed. I am able to create the Image Button as follow. But the Image comes larger as its size. How to fix its size according to the button's size.
ImageButton b0=new ImageButton(this);
b0.setMaxWidth(100);
b0.setMinimumWidth(100);
b0.setMaxHeight(80);
b0.setBackgroundResource(R.drawable.tattoo0);
tattooListView.addView(b0);
Thanks in advance
You can try:
b0.setScaleType(ScaleType.FIT_XY);
Hope it helps
ScaleType Wont work for Background it will work for Source Image. Source image you can set By src property in xml, or programmatically by setImage() methods as below:
public void setImageBitmap (Bitmap bm)
public void setImageDrawable (Drawable drawable)
public void setImageResource (int resId)
This code helped me to achieve my target.
ImageButton btn = new ImageButton(getApplicationContext());
String str=String.format("drawable/theimage");
int imageResource = getResources().getIdentifier(str, null, getPackageName());
BitmapDrawable drawable = (BitmapDrawable)getApplicationContext().getResources().getDrawable(imageResource);
Bitmap bitmap = drawable.getBitmap();
bitmap = Bitmap.createScaledBitmap(bitmap, 100, 80, true);
btn.setBackgroundColor(80000000);
btn.setImageBitmap(bitmap);
btn.setTag(1);
linearlayoutview.addView(btn);

Load image in device independent and screen independent fashion into a layout view using 1.6 SDK

I'm having trouble getting an asset image to scale up when I load it. The new call to BitmapDrawable(Resources, BitmapDrawable) is not available on 1.6 SDK.
Is there a workaround to load the BitmapDrawable the old way and then somehow manipulate it? I have tried calling setTargetDensity() to no avail. My code (which doesn't scale properly) is:
ImageView iv = (ImageView)view.findViewById(R.id.image);
iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));
I found a way that worked, after doing some good old RTFM.
The following code works:
ImageView iv = (ImageView)view.findViewById(R.id.image);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = true;
opts.inDensity = DisplayMetrics.DENSITY_MEDIUM;
Rect padding = new Rect();
opts.inTargetDensity = view.getResources().getDisplayMetrics().densityDpi;
Bitmap bm = BitmapFactory.decodeStream(view.getContext().getAssets().open(path), padding, opts);
iv.setImageBitmap(bm);
For background see http://d.android.com/guide/practices/screens_support.html

Categories

Resources