此项目的视频
我创建了一个带有背景(png)图片和编辑文本的imageview。所以它们都在linerlayout中,所以如果我在edittext中输入值,我会得到一个完全不同的图像。我这样做是因为linearlayout表示“信用卡”(作为imageview的backround)和不同的值(作为edittext中的值)。
我能够将linearlayout转换成带有位图的图像,因此每次我通过按preview在edittext中输入不同用户的值时,我都会生成一张用户信用卡。
问题是,现在我想上传到我的firebase的具体形象。我已经添加了依赖项,并尝试从本地实习生内存中上传一些随机图片,但我还没有想到如何将转换后的图像(实际上是普通图像)上传到firebase中,而不必将图像存储到我的内部存储器中。
我尝试将从内存上传的内容与实际的转换图像类结合起来,但是这个过程需要uri,而(转换的linearlayout)图像没有uri。
这是我的java类:
public class DashboardAddBanking extends AppCompatActivity {
EditText e1, e2, e3, e4, e5, e6, e7, e8, e9;
TextView t1, t2, t3, t4, t5, t6;
Button preview, save;
ImageView credit_card, imgResultImage;
RelativeLayout layout_view;
Bitmap image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard_add_banking);
e1 = (EditText) findViewById(R.id.et1); //Code 1
e2 = (EditText) findViewById(R.id.et2); //Code 2
e3 = (EditText) findViewById(R.id.et3); //Code 3
e4 = (EditText) findViewById(R.id.et4); //Code 4
e5 = (EditText) findViewById(R.id.et5); //name
e6 = (EditText) findViewById(R.id.et6); //month
e7 = (EditText) findViewById(R.id.et7); //year
e8 = (EditText) findViewById(R.id.et8); //cvv
e9 = (EditText) findViewById(R.id.et9); //bank name
t1 = (TextView) findViewById(R.id.card_number);
t2 = (TextView) findViewById(R.id.card_holder);
t3 = (TextView) findViewById(R.id.month);
t4 = (TextView) findViewById(R.id.year);
t5 = (TextView) findViewById(R.id.cvv);
t6 = (TextView) findViewById(R.id.bankname);
preview = (Button) findViewById(R.id.btn_preview_credit_card);
save = (Button) findViewById(R.id.btn_save_credit_card);
credit_card = findViewById(R.id.credit_card);
imgResultImage = findViewById(R.id.imgResultImage);
layout_view = findViewById(R.id.rl1);
//Preview card
preview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_down);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rl1);
relativeLayout.setAnimation(animation);
String code1, code2, code3, code4;
String name, month, year, cvv, bankname;
code1 = e1.getText().toString();
code2 = e2.getText().toString();
code3 = e3.getText().toString();
code4 = e4.getText().toString();
t1.setText(code1 + "\t" + code2 + "\t" + code3 + "\t" + code4 + "\t");
name = e5.getText().toString();
t2.setText(name);
month = e6.getText().toString();
t3.setText(month);
year = e7.getText().toString();
t4.setText(year);
cvv = e8.getText().toString();
t5.setText(cvv);
bankname = e9.getText().toString();
t6.setText(bankname);
}
});
//Convert layout to image
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image = getBitmapFromView(layout_view);
imgResultImage.setImageBitmap(image);
}
});
}
private Bitmap getBitmapFromView(View view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null) {
//has background drawable, then draw it on the canvas
bgDrawable.draw(canvas);
} else {
//does not have background drawable, then draw white background on the canvas
canvas.drawColor(Color.WHITE);
}
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;
}
}
这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".dashboard.banking.DashboardAddBanking">
<RelativeLayout
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center"
>
<ImageView
android:id="@+id/credit_card"
android:layout_width="335dp"
android:layout_height="185dp"
android:background="@drawable/credit_card"
/>
<TextView
android:id="@+id/bankname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bank name"
android:textStyle="bold"
android:textSize="15sp"
android:textColor="@color/white"
android:layout_marginTop="20dp"
android:layout_marginStart="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/card_number"
android:textSize="18sp"
android:layout_below="@+id/bankname"
android:textColor="@color/white"
android:layout_marginTop="20dp"
android:layout_marginStart="40dp"
android:id="@+id/card_number"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cardholder"
android:textSize="15sp"
android:layout_below="@+id/card_number"
android:textColor="@color/white"
android:layout_marginTop="20dp"
android:layout_marginStart="40dp"
android:id="@+id/card_holder"
/>
<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/card_holder"
android:layout_below="@+id/card_number"
android:layout_marginTop="20dp"
android:layout_marginStart="40dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="06"
android:textColor="@android:color/white"
android:textSize="15sp"/>
<TextView
android:id="@+id/mm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MM"
android:textColor="@android:color/white"
android:textSize="12sp"/>
</LinearLayout>
<TextView
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/ll1"
android:layout_below="@+id/card_number"
android:layout_marginTop="20dp"
android:layout_marginStart="5dp"
android:text="/"
android:textColor="@color/white"
android:textSize="15sp"
/>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/div"
android:layout_below="@+id/card_number"
android:layout_marginTop="20dp"
android:layout_marginStart="10dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="21"
android:textColor="@android:color/white"
android:textSize="15sp"/>
<TextView
android:id="@+id/yy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YY"
android:textColor="@android:color/white"
android:textSize="12sp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CVV"
android:layout_toEndOf="@id/ll2"
android:layout_marginTop="20dp"
android:layout_marginStart="20dp"
android:layout_below="@id/card_number"
android:textColor="@android:color/white"
android:textSize="15sp"/>
<TextView
android:id="@+id/cvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - - -"
android:layout_toEndOf="@id/ll2"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:layout_below="@id/card_number"
android:textColor="@android:color/white"
android:textSize="12sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rl2"
android:layout_below="@+id/rl1"
android:layout_marginTop="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="16 digit number"
android:layout_marginStart="20dp"
android:textColor="@color/primaryText"
android:textSize="12sp"
android:id="@+id/tv1"/>
<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="XXXX"
android:inputType="number"
android:maxLength="4"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:textColorHint="@color/mainText"/>
<EditText
android:id="@+id/et2"
android:layout_toEndOf="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="XXXX"
android:inputType="number"
android:maxLength="4"
android:layout_marginStart="25dp"
android:layout_marginTop="15dp"
android:textColorHint="@color/mainText"/>
<EditText
android:id="@+id/et3"
android:layout_toEndOf="@+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="XXXX"
android:inputType="number"
android:maxLength="4"
android:layout_marginStart="25dp"
android:layout_marginTop="15dp"
android:textColorHint="@color/mainText"/>
<EditText
android:id="@+id/et4"
android:layout_toEndOf="@+id/et3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="XXXX"
android:inputType="number"
android:maxLength="4"
android:layout_marginStart="25dp"
android:layout_marginTop="15dp"
android:textColorHint="@color/mainText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cardholder Name"
android:id="@+id/tv2"
android:layout_below="@id/et1"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:textColor="@color/primaryText"
android:textSize="12sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Card holder"
android:id="@+id/et5"
android:layout_below="@+id/tv2"
android:layout_marginStart="20dp"
android:textColorHint="@color/mainText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expire"
android:id="@+id/tv3"
android:layout_below="@id/et5"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:textColor="@color/primaryText"
android:textSize="12sp"/>
<EditText
android:id="@+id/et6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="MM"
android:inputType="number"
android:maxLength="2"
android:layout_below="@+id/tv3"
android:layout_marginStart="20dp"
android:textColorHint="@color/mainText"/>
<EditText
android:id="@+id/et7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/et6"
android:hint="YY"
android:inputType="number"
android:maxLength="2"
android:layout_below="@+id/tv3"
android:layout_marginStart="20dp"
android:textColorHint="@color/mainText"/>
<TextView
android:id="@+id/tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CVV"
android:layout_below="@id/et6"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:textColor="@color/primaryText"
android:textSize="12sp"/>
<EditText
android:id="@+id/et8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="XXX"
android:inputType="number"
android:maxLength="3"
android:layout_below="@+id/tv4"
android:layout_marginStart="20dp"
android:textColorHint="@color/mainText"/>
<TextView
android:id="@+id/tv5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bank name"
android:layout_below="@id/et6"
android:layout_toEndOf="@+id/tv4"
android:layout_marginStart="200dp"
android:layout_marginTop="30dp"
android:textColor="@color/primaryText"
android:textSize="12sp"/>
<EditText
android:id="@+id/et9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/et8"
android:hint="Your Bank"
android:layout_below="@+id/tv5"
android:layout_marginStart="180dp"
android:textColorHint="@color/mainText"/>
</RelativeLayout>
<Button
android:id="@+id/btn_preview_credit_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rl2"
android:layout_alignParentStart="true"
android:layout_marginStart="50dp"
android:layout_marginTop="20dp"
android:background="@drawable/button_save_round"
android:text="Preview"
android:textColor="@color/white"
android:textSize="15sp" />
<ImageView
android:id="@+id/imgResultImage"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_toEndOf="@+id/btn_preview_credit_card"
android:layout_below="@+id/rl2"
android:layout_marginTop="20dp"
android:layout_marginStart="5dp"/>
<Button
android:id="@+id/btn_save_credit_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rl2"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@+id/imgResultImage"
android:layout_marginStart="250dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="50dp"
android:background="@drawable/button_save_round"
android:text="Save"
android:textColor="@color/white"
android:textSize="15sp" />
</RelativeLayout>
你能帮帮我吗?我会非常感激的,因为我现在正试图找到一个想法几天了。此项目的视频
暂无答案!
目前还没有任何答案,快来回答吧!