ich eine benutzerdefinierte Kamera-App haben, die eine zentrierte Rechteck Ansicht haben, wie Sie unten sehen können:Android Individuelle Kamera - Crop Bild innerhalb Rechteck
Wenn ich ein Bild aufnehmen Ich will alles draußen ignorieren das Rechteck. Die Aussicht hat keine Verbindung mit der Kamera Vorschau oder Surface in meinem XML-Ansicht wie folgt:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/cameraview"
android:name="com.kut.camera.KutCameraFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<View android:id="@+id/viewTamanho"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="400px"
android:layout_marginTop="300px"
android:layout_marginStart="70px"
android:layout_marginEnd="70px"
android:background="@drawable/border" />
<RelativeLayout
android:id="@+id/rel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
android:background="@android:color/black"
android:orientation="vertical"
android:padding="10dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textViewReferan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Evidência"
android:textColor="@android:color/white"
android:textSize="16sp" />
<Button
android:id="@+id/button_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@android:color/transparent"
android:text="Sair"
android:textColor="#2799CF" />
</RelativeLayout>
<LinearLayout
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/islem_value_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carregando..." />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:alpha="0.9"
android:background="@android:color/black"
android:padding="10dp" >
<ImageView
android:id="@+id/imageView_foto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/camera" />
<ImageView
android:id="@+id/imageView_photo"
android:layout_width="80dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:padding="5dp"
android:scaleType="fitCenter"
android:src="@drawable/fotoicon" />
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
Kann mir jemand helfen, wie man richtig das Bild zuzuschneiden? Ich habe versucht, eine neue Bitmap basiert auf meiner XML zu erstellen, aber offensichtlich hat es nicht funktioniert, so etwas wie:
Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//.../
Bitmap imagemOriginal = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap imagemCortada = Bitmap.createBitmap(imagemOriginal, 70, 400, imagemOriginal.getWidth() - 70,
imagemOriginal.getHeight() - 400);
//.../
}
Ich habe diese Anfangswerte für x und y, und versucht (zu subtrahieren basierend auf XML-Werte von anzeigen Bezug auf marginTop, Bottom, etc ...) von Breite und Höhe, aber ich hatte keinen Erfolg, weil ich nicht weiß, wie man die Koordinaten mit den Bildkoordinaten aus der Kamera abgleichen kann. Auch scheint es für mich Bitmap.createBitmap beschränkt Zuschnitt, offenbar kann ich nicht direkt auf ein Rechteck zuschneiden.
Was genau hat nicht funktioniert? Das Hauptproblem mit Ihrem Code besteht darin, dass die ursprüngliche Bitmap möglicherweise sehr groß ist und in Ihrer App nicht genügend Arbeitsspeicher zur Verfügung steht. Vielleicht hast du deine Kamera nicht richtig konfiguriert, insbesondere "setPictureSize()" nicht korrekt aufgerufen. –
Ich sagte, ich weiß nicht, wie man es korrekt zuschneidet, um die Koordinaten des Rechtecks anzupassen. Sie sehen in Bitmap.createBitmap Ich setze Anfangswerte für x und y und versuche, Werte von Breite und Höhe zu subtrahieren, aber ich kann die korrekten Werte nicht herausfinden. Ich lege diese Werte einfach dort hin, denn das stelle ich aus marginTop, marginBottom in XML. Wie kann ich wissen, welche Werte für * setPictureSize() * korrekt sind, wenn die Bildschirmdiagonalen im Bereich liegen? –
there ist das Erbauen ui Bibliothek https://android-arsenal.com/details/1/207 chk es heraus, wenn Sie es verwenden können ... oder irgendeine Inspiration nehmen –