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
Related
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.
I see that depending on how an image is set as the logo for ActionBar's home button, the image appears scaled down.
Image is scaled when using one of the following:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
actionBar.setLogo(new BitmapDrawable(bmp));
Bitmap bmp = BitmapFactory.decodeFile(filePath);
actionBar.setLogo(new BitmapDrawable(bmp));
Image is NOT scaled, it looks OK when using one of the following:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
actionBar.setLogo(getResources(), new BitmapDrawable(bmp));
Bitmap bmp = BitmapFactory.decodeFile(filePath);
actionBar.setLogo(getResources(), new BitmapDrawable(bmp));
actionBar.setLogo(R.drawable.logo)
For all cases, I call actionBar.setDisplayUseLogoEnabled(true).
Compared to 1 and 2, 3 and 4 respectively pass Resources parameter to setLogo.
I would like to understand why passing Resources influence the logo size.
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!?
I've encountered totally bizarre behavior in the way Android loads bitmaps into ImageView. For example, I have a 500x313 image file called urimg_01.jpg. With this code:
img.setImageResource(R.drawable.urimg_01);
Bitmap bitmap = ((BitmapDrawable) img.getDrawable()).getBitmap();
Log.v(TAG,"---------------------> bitmap width = "+bitmap.getWidth());
Log.v(TAG,"---------------------> bitmap height = "+bitmap.getHeight());
the ImageView bitmap is 750x470. (I have a Nexus S with 480x800 display.)
With this code, which reads a copy of the same file located in getFilesDir():
Log.v(TAG,"image file is "+filelist[0].getAbsolutePath());
FileInputStream fis = new FileInputStream(filelist[0]);
FileDescriptor fd = fis.getFD();
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
if (bitmap != null) {
Log.v(TAG,"---------------------> bitmap width = "+bitmap.getWidth());
Log.v(TAG,"---------------------> bitmap height = "+bitmap.getHeight());
img.setImageBitmap(bitmap);
fis.close();
}
the ImageView bitmap is 500x313, as expected.
In the case of setImageResource(), where the devil is it getting 750x470 from?? And how do I get it to use the correct dimensions for resources in drawable?
Your resource is being scaled up because it's probably stored in a medium density folder and you're using a high density device. See Bitmap getWidth returns wrong value for details.
here you get your bitmap
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
now scale it according to device height and width
Display display=this.getWindowManager().getDefaultDisplay();
int w=display.getWidth();
int h=display.getHeight();
Bitmap newBitmap=Bitmap.createScaledBitmap(oldBitmap, w, h, false);
//now setImage to background with new Bitmap
One important thing "this" should be activity context
:) cheers
I am resizing image and rotating it using Matrix:
Matrix mtx = new Matrix();
if(orientation>0) {
mtx.postRotate(orientation);
Log.d(TAG,"image rotated: "+orientation);
}
if(scale<1) {
mtx.postScale(scale,scale);
Log.d(TAG,"image scaled: "+scale);
}
bmp = Bitmap.createBitmap(bm_orig, 0, 0, width, height, mtx, true);
bm_orig.recycle();
bmp.compress(Bitmap.CompressFormat.JPEG,95,output);
bmp.recycle();
When bmp_orig is taken, used 3.2 Mpx Camera, image resized and rotated looks normal.
But when source is 4 Mpx or bigger, result after resizing has barely-noticeable linear noise
I dont know, why does this noise appear, and how to remove it.
Any idea?
May be another way to resize and rotate?
Found that this problem is related with source and resulting image size.
Solved it, when check image size before loading it, and then load halfsized image, if source image size is more than 2 times bigger than resulting size is needed.
BitmapFactory.Options options_to_get_size = new BitmapFactory.Options();
options_to_get_size.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, null, options_to_get_size);
int load_scale = 1; // load 100% sized image
int width_tmp=options_to_get_size.outWidth
int height_tmp=options_to_get_size.outHeight;
while(width_tmp/2>maxW && height_tmp/2>maxH){
width_tmp/=2;//load half sized image
height_tmp/=2;
load_scale*=2;
}
Log.d(TAG,"load inSampleSize: "+ load_scale);
//Now load image with precalculated scale. scale must be power of 2 (1,2,4,8,16...)
BitmapFactory.Options option_to_load = new BitmapFactory.Options();
option_to_load.inSampleSize = load_scale;
((FileInputStream)input).getChannel().position(0); # reset input stream to read again
Bitmap bm_orig = BitmapFactory.decodeStream(input,null,option_to_load);
input.close();
//now you can resize and rotate image using matrix as stated in question