我想将位图的大小精确地减少到200kb.我从SD卡中获取一张图像,将其压缩并再次使用不同的名称将其保存到另一个目录中的SD卡中.压缩工作正常(3 mb像图像被压缩到大约100 kb).我为此编写了以下代码行:
String imagefile ="/sdcard/DCIM/100ANDRO/DSC_0530.jpg";
Bitmap bm = ShrinkBitmap(imagefile, 300, 300);
//this method compresses the image and saves into a location in sdcard
Bitmap ShrinkBitmap(String file, int width, int height){
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);
if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio)
{
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
bmpFactoryOptions.inJustDecodeBounds = false; …
Run Code Online (Sandbox Code Playgroud) 我试图将一些类和XML文件提交给SVN但我不断收到此错误消息:
svn:E200007:提交失败(详情如下):svn:E200007:CHECKOUT只能在版本资源上执行[此时].svn:E175002:"/svn/SriLankaLottery-app/!svn/rvr/31/trunk/DealsDirect/src/com/elottery/Login.java"上的CHECKOUT请求失败
我也尝试更新代码然后提交,但它仍然无法正常工作.
我在我的应用程序中使用导航抽屉使用Android滑动菜单,而在应用程序中使用碎片而不是活动.当我打开抽屉时,单击片段出现的项目.我使用以下代码从一个片段移动到另一个片段:
Fragment fragment = null;
fragment = new GalleryFragment(selectetdMainMenu.getCategoryID());
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.addToBackStack("menuFrag");
ft.add(R.id.frame_container, fragment, "menuFrag");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
Run Code Online (Sandbox Code Playgroud)
通过这种方式,我可以从一个片段转到另一个片段但是我无法按下后退按钮上的前一个片段.我设法提出这个代码来处理MainActivity中的反压,其中Drawer初始化:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
if (keyCode == KeyEvent.KEYCODE_BACK) {
Fragment fragment_byTag = fragmentManager.findFragmentByTag("menuFrag");
Fragment menuFragment_by_tag = fragmentManager.findFragmentByTag("galleryFrag");
Fragment commentsFrag_by_tag = fragmentManager.findFragmentByTag("commentsFrag");
Fragment dealDetail = fragmentManager.findFragmentByTag("promoFrag");
if(commentsFrag_by_tag != null){
if (commentsFrag_by_tag.isVisible()) {
Log.e("comments back ", " clicked");
//menuDetailsFrag.onBackPressed();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().remove(commentsFrag_by_tag).commit();
fragmentManager.beginTransaction().show(menuFragment_by_tag).commit();
}
}else if(menuFragment_by_tag.isVisible()){
Log.e("menu back ", " clicked");
menuDetailsFrag.onBackPressed();
FragmentManager fragmentManager …
Run Code Online (Sandbox Code Playgroud) 我已成功将tesseract集成到我的Android应用程序中,它会读取我捕获的任何图像,但准确度却非常低.但大部分时间我都没有在捕获后获得正确的文本,因为感兴趣区域周围的一些文本也被捕获.
所有我想要阅读的都是来自矩形区域的所有文本,准确无需捕获矩形的边缘.我做了一些研究并在stackoverflow上发布了这两次,但仍然没有得到满意的结果!
以下是我发的2篇帖子:
/sf/ask/1166445311/?noredirect=1#comment23973954_16663504
我不确定是继续使用tesseract还是使用openCV
我在我的Android应用程序中包含了Open Street Maps.在mapview中,用户应该能够在地图完全加载后捕获屏幕.但是,即使仍在加载mapview,用户也可以捕获图像.有人能告诉我如何检测mapview何时完全加载?
下面是我加载mapview的代码:
public class MainActivity extends Activity {
MapView mapView;
MyLocationOverlay myLocationOverlay = null;
ArrayList<OverlayItem> anotherOverlayItemArray;
protected ItemizedOverlayWithBubble<ExtendedOverlayItem> itineraryMarkers;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
final ArrayList<ExtendedOverlayItem> waypointsItems = new ArrayList<ExtendedOverlayItem>();
itineraryMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, waypointsItems, mapView, new ViaPointInfoWindow(R.layout.itinerary_bubble, mapView));
mapView.getOverlays().add(itineraryMarkers);
mapView.setTileSource(TileSourceFactory.MAPNIK);
mapView.setBuiltInZoomControls(true);
MapController mapController = mapView.getController();
mapController.setZoom(1);
GeoPoint point2 = new GeoPoint(51496994, -134733);
mapController.setCenter(point2);
Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000);
ExtendedOverlayItem overlayItem = new ExtendedOverlayItem("Title Test Loc", "Desc", myPoint1, …
Run Code Online (Sandbox Code Playgroud) 我是Android的OpenCV新手.我正在尝试将C++代码转换为Java.我陷入了某些困境,我无法继续.
std::vector<cv::Vec4i> lines;
cv::HoughLinesP(bw, lines, 1, CV_PI/180, 70, 30, 10);
// Expand the lines
for (int i = 0; i < lines.size(); i++)
{
cv::Vec4i v = lines[i];
lines[i][0] = 0;
lines[i][1] = ((float)v[1] - v[3]) / (v[0] - v[2]) * -v[0] + v[1];
lines[i][2] = src.cols;
lines[i][3] = ((float)v[1] - v[3]) / (v[0] - v[2]) * (src.cols - v[2]) + v[3];
}
Run Code Online (Sandbox Code Playgroud)
我改变了一半..直到TODO
MatOfInt4 lines= new MatOfInt4();
Imgproc.HoughLinesP(bw, lines, 1, Math.PI/180, 70, 30, 10);
int[] lineArray = lines.toArray();
// …
Run Code Online (Sandbox Code Playgroud) 我已成功将城市飞艇推送通知集成到我的Android应用程序中.我遇到了一个问题,就是apID在首次启动时变为null,然后在第二次启动时,apId正确.
这是我抓住apId的方式:
String apid = PushManager.shared().getAPID();
Run Code Online (Sandbox Code Playgroud)
这是我用过的类:
public class MyApplication extends Application {
public static SharedPreferences PREFS_TOKEN;
public static final String PREFERENCE = "UrbanAirship";
public static String tokenKey;
@Override
public void onCreate(){
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
UAirship.takeOff(this, options);
PushManager.enablePush();
Logger.logLevel = Log.VERBOSE;
// use CustomPushNotificationBuilder to specify a custom layout
CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder();
nb.statusBarIconDrawableId = R.drawable.paw;// custom status bar icon
nb.layout = R.layout.notification;
nb.layoutIconDrawableId = R.drawable.paw;// custom layout icon
nb.layoutIconId = R.id.icon;
nb.layoutSubjectId = R.id.subject;
nb.layoutMessageId = R.id.message; …
Run Code Online (Sandbox Code Playgroud) 我的XML工作得很好,它有一个列表视图,一组文本视图,图像视图和按钮.然后我为整个布局添加了滚动视图.Listview停止运行,然后我添加了一个自定义类,以使其工作.现在一切都按预期工作,但问题是当xml加载时布局的顶部不可见,我必须向上滚动才能看到它的顶部.我的问题与此相同,但仍然提供的解决方案不起作用:ScrollView不显示顶部 这是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_default"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/navigation_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/navigation"
android:baselineAligned="false"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1" >
<TextView
android:id="@+id/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#057afb"
android:textSize="19sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/navigation_layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/navigation_layout"
android:baselineAligned="false"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingTop="10dp" >
<ImageView
android:id="@+id/app_icon"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="14dp"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/btn_install"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/app_icon"
android:layout_marginRight="36dp"
android:background="@drawable/list_apps_install_button_selector" />
<TextView
android:id="@+id/txt_desc" …
Run Code Online (Sandbox Code Playgroud) 我有一个包含约30项的列表视图.当我向下滚动它时,它只是到达列表的最底部,并且在用户触摸列表时不会停止.
是否有一种方法可以在触摸列表视图时停止滚动,同时用户应该能够使用onItemClick(已处理)进行导航.
谢谢!
我使用以下代码找到从Android相机中找到捕获图像的最大矩形:
private static Mat findLargestRectangle(Mat original_image) {
Mat imgSource = original_image;
Bitmap bmpOriOut = Bitmap.createBitmap(imgSource.cols(), imgSource.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgSource, bmpOriOut);
try {
bmpOriOut.compress(CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/mediaAppPhotos/original.jpg"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//convert the image to black and white, commenting this wont crash
Imgproc.cvtColor(imgSource, imgSource, Imgproc.COLOR_BGR2RGB);
//convert the image to black and white does (8 bit), commenting this crashes
Imgproc.Canny(imgSource, imgSource, 50, 50);
//apply gaussian blur to smoothen lines of dots, commenting this crashes
Imgproc.GaussianBlur(imgSource, …
Run Code Online (Sandbox Code Playgroud) 我有一个哈希映射类型数组列表:
public static ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
Run Code Online (Sandbox Code Playgroud)
它有一些ID和名称,如下所示:
这是用于循环的代码:
for (HashMap<String, String> map : mylist)
for (Entry<String, String> entry : map.entrySet())
if(entry.getValue().contains(typedText)){
map1 = new HashMap<String, String>();
map1.put("id", entry.getKey());
map1.put("name", entry.getValue());
mylist1.add(map1);
}
Run Code Online (Sandbox Code Playgroud)
问题是在这一行:
for (Entry<String, String> entry : map.entrySet())
Run Code Online (Sandbox Code Playgroud)
map.entrySet()
显示正确的ID和名称,如下所示:
但只有名称可用'条目':
entry.getKey()
总是返回文本'name'这个键,并entry.getValue()
返回'Katie Bailey'这个值.
我的问题是为什么我没有使用entry.getKey()获取密钥?为什么每次迭代时总是将'name'作为键?
我想在我的Android应用程序中包含一个自定义字体.这是我遵循的教程,这似乎适用于许多人:http://tharindudassanayake.wordpress.com/2012/02/25/use-sinhala-fonts-for-your-android-app/
这是我尝试过的方式:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/sinhala_font"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="wdhqfndajka"
android:textSize="25sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
码:
TextView txt = (TextView) findViewById(R.id.sinhala_font);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/amal.TTF");
txt.setTypeface(font);
Run Code Online (Sandbox Code Playgroud)
不幸的是应用程序崩溃(由于原生字体无法制作),我在我的日志猫中得到以下内容:
10-27 11:39:14.311: E/AndroidRuntime(28133): FATAL EXCEPTION: main
10-27 11:39:14.311: E/AndroidRuntime(28133): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sinhala/com.example.sinhala.MainActivity}: java.lang.RuntimeException: native typeface cannot be made
10-27 11:39:14.311: E/AndroidRuntime(28133): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
10-27 11:39:14.311: E/AndroidRuntime(28133): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
10-27 11:39:14.311: E/AndroidRuntime(28133): at android.app.ActivityThread.access$600(ActivityThread.java:128)
10-27 11:39:14.311: E/AndroidRuntime(28133): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
10-27 11:39:14.311: E/AndroidRuntime(28133): …
Run Code Online (Sandbox Code Playgroud)