我为 Android Wear 制作了一个 Watch Face。
但问题是图像缩放。当我调整背景、标记和小工具的图像时,它们的质量会降低。
例如,我将 480x480 背景图像放在 drawable-nodpi 文件夹中(我也尝试过其他 dpi),然后像这样重新缩放它:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
Bitmap bgImage = BitmapFactory.decodeResource(context.getResources(), R.drawable.ticks_1, options);
bgImage = Bitmap.createScaledBitmap(bgImage , width, height, false);
图片如下:
这是我在 watch 上看到的:
我是不是在调整大小方面做错了什么?
最佳答案
我找到了解决方案 here效果很好。
这是缩放图像的部分代码:
public Bitmap getResizedBitmap(Bitmap bitmap, int newWidth, int newHeight) {
Bitmap resizedBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
float scaleX = newWidth / (float) bitmap.getWidth();
float scaleY = newHeight / (float) bitmap.getHeight();
float pivotX = 0;
float pivotY = 0;
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);
Canvas canvas = new Canvas(resizedBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));
return resizedBitmap;
}
关于android - 位图缩放破坏质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222769/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
最近,我安装了OSXMavericks,它似乎弄乱了我的开发环境。我在运行“railsnewfirst_app”后收到此消息:Youruseraccountisn'tallowedtoinstalltothesystemRubygems.Youcancancelthisinstallationandrun:bundleinstall--pathvendor/bundletoinstallthegemsinto./vendor/bundle/,oryoucanenteryourpasswordandinstallthebundledgemstoRubygemsusingsudo.Pass
升级到OSXYosemite后,我现有的pow.cx安装不起作用。升级到最新的pow.cx无效。通过事件监视器重新启动它也没有成功。 最佳答案 卸载(!)并重新安装解决了这个问题。curlget.pow.cx/uninstall.sh|shcurlget.pow.cx|sh 关于ruby-on-rails-OSXYosemite更新破坏了pow.cx,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q
我在新的Rails应用程序(3.2.3)中运行迁移时遇到了问题。我们正在使用postrgres9.1.3和-pg(0.13.2)-当我运行rakedb:create,然后运行rakedb:migrate,我得到->1.9.3-p194(master)rakedb:migrate--trace**Invokedb:migrate(first_time)**Invokeenvironment(first_time)**Executeenvironmentrakeaborted!PG::Error:ERROR:relation"roles"doesnotexistLINE4:WHEREa
我在我的应用程序中使用to_param创建自定义URL(此自定义路径包含斜杠):classMachine问题是,自从Rails4.1.2行为发生变化并且Rails不允许在URL中使用斜线(当使用自定义URL时),所以它转义了斜线。我有这样的路线:Rails.application.routes.drawdoscope"(:locale)",locale:/#{I18n.available_locales.join("|")}/doresources:machines,except::destroydocollectiondoget:searchget'search/:ad_type(/
Web上有许多示例(例如http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails)展示了如何使用Builder制作漂亮的RSS提要。规范模板是这样的:xml.instruct!:xml,:version=>"1.0"xml.rss:version=>"2.0"doxml.channeldoxml.title"YourBlogTitle"xml.description"Ablogaboutsoftwareandchocolate"xml.linkposts_urlforpostin@postsxml.itemdoxml.t
在Ruby中,一个对象可以销毁另一个对象吗?例如:classCreaturedefinitialize@energy=1endattr_accessor:energyendclassCrocodile鳄鱼吃掉一个生物并吸收它的能量后,该生物应该不复存在。但是上面的代码并没有摧毁这个生物。我知道如果我说fish=nil,变量fish引用的对象将被垃圾回收。但是在Crocodile的eat方法中说creature=nil并不能实现这一点。另一种表达方式在croc.eat内部,我可以说“既然变量‘fish’被传递给我,当我完成后,我要将‘fish’设置为nil?”更新:问题已解决我基本上采用
我已更新到Rails2.3.10、Rack1.2.1,现在我的所有即时消息都没有显示。我发现在重定向期间,通知是这样传递的redirect_to(@user,:notice=>"Sorrytherewasanerror")在我看来闪存哈希是空的!map:ActionController::Flash::FlashHash{}但是您可以在Controller中看到该消息。是什么原因?session{:home_zip=>"94108",:session_id=>"xxx",:flash=>{:notice=>"Sorrytherewasanerror"},:user_credential
我正在运行RubyonRails3,我想使用Paperclip插件/gem降低上传图像的质量。我该怎么做?此时在我的模型文件中我有:has_attached_file:avatar,:styles=>{:thumb=>["50x50#",:jpg],:medium=>["250x250#",:jpg],:original=>["600x600#",:jpg]}这会将图像转换为.jpg格式并设置尺寸。 最佳答案 尝试使用convert_options。has_attached_file:avatar,:styles=>{:thumb=
是否有从哈希中删除键值对的非破坏性方法?例如,如果你这样做了original_hash={:foo=>:bar}new_hash=original_hashnew_hash=new_hash.reject{|key,_|key==:foo}或original_hash={:foo=>:bar}new_hash=original_hashnew_hash=new_hash.dupnew_hash.delete(:foo)然后original_hash没有改变,new_hash改变了,但是它们有点冗长。但是,如果你这样做了original_hash={:foo=>:bar}new_hash