I think I found the problem...and it looks like it's an Android bug. Drawable.createFromStream() doesn't take as parameter a Resources object, and later it calls Drawable.createFromResourceStream() passing 'null' as the Resources parameter. >From my understanding the resources are then used to ensure that the drawable will set its target density correctly, but by being 'null' some default density is used.
On Sat, Feb 18, 2012 at 2:40 PM, YuviDroid <[email protected]> wrote: > Hi Dianne, > > thanks for your reply. The problem is that I'm using > RemoteViews.setImageViewUri(), so I don't have a bitmap object to set the > density. > The Uri I'm using is "content://..." which reaches my ContentProvider at > the method openFile(Uri,String). > > I looked at the Android source code and I see that ImageView.setImageUri() > uses resolveUri(), and for the content scheme it > calls > Drawable.createFromStream(mContext.getContentResolver().openInputStream(mUri), > null); > which calls my openFile() method, which I implemented like this: > public ParcelFileDescriptor openFile(Uri uri, String mode) throws > FileNotFoundException { > File file = new File(getContext().getFilesDir(), "MyFile.png"); > > return ParcelFileDescriptor.open(file, > ParcelFileDescriptor.MODE_READ_ONLY); > } > > I don't see where I can change the density to use. :( > > > Thanks, > Yuvi > > > On Sat, Feb 18, 2012 at 2:19 AM, Dianne Hackborn <[email protected]>wrote: > >> Set the desired density of your bitmap: >> http://developer.android.com/reference/android/graphics/Bitmap.html#setDensity(int) >> >> >> On Fri, Feb 17, 2012 at 12:56 PM, YuviDroid <[email protected]> wrote: >> >>> Hi, >>> >>> sorry to resurrect this post...but I got into a similar problem. And as >>> the OP did, I'm using RemoteViews.setImageViewUri() to set my image on the >>> appwidget. However I noticed that my image is being scaled according to the >>> screen density. >>> >>> So, for example, on an XHDPI screen, if I have a bitmap which is 100x100 >>> and I set it using setImageViewBitmap() I get the image to look as 100x100. >>> However, if I store that bitmap into a png on disk, and then use >>> setImageViewUri() my bitmap is displayed as 50x50. >>> >>> Do you know if there is a way to change this behavior? (i.e. if my image >>> is 100x100 I'd like it to remain 100x100 also after it is decoded). >>> Maybe there is a way to force some density on the ImageView itself? >>> >>> My only workaround (which sucks..) is to scale-up the bitmap before >>> storing on disk so that when it is being decoded I get back my original >>> size. But in this way I use more memory to save the image and I also loose >>> image quality..:( >>> >>> I hope someone can help me! >>> Thanks, >>> Yuvi >>> >>> On Mon, Aug 1, 2011 at 8:05 PM, Ash McConnell >>> <[email protected]>wrote: >>> >>>> Thanks Kostya and Dianne, setUri works as expected. I had to create >>>> the files using context.openFileOutput. Unfortunately that means I loose >>>> the ability to use directories. I can't see a "Java" way to set permission >>>> on files, it can be done with native methods, but that seems like overkill. >>>> I'll do some more googling. >>>> >>>> Thanks again for the help, I was worried that this problem might have >>>> been a show-stopper. >>>> Ash >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to >>>> [email protected] >>>> To unsubscribe from this group, send email to >>>> [email protected] >>>> For more options, visit this group at >>>> http://groups.google.com/group/android-developers?hl=en >>>> >>> >>> >>> >>> -- >>> YuviDroid >>> Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a >>> widget to quickly access your favorite apps and contacts!) >>> http://android.yuvalsharon.net >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to [email protected] >>> To unsubscribe from this group, send email to >>> [email protected] >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >>> >> >> >> >> -- >> Dianne Hackborn >> Android framework engineer >> [email protected] >> >> Note: please don't send private questions to me, as I don't have time to >> provide private support, and so won't reply to such e-mails. All such >> questions should be posted on public forums, where I and others can see and >> answer them. >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > > -- > YuviDroid > Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget > to quickly access your favorite apps and contacts!) > http://android.yuvalsharon.net > > -- YuviDroid Check out Launch-X <http://android.yuvalsharon.net/launchx.php> (a widget to quickly access your favorite apps and contacts!) http://android.yuvalsharon.net -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

