gpt4 book ai didi

java - Android:是否可以将图像上传到服务器内的文件夹中?

转载 作者:行者123 更新时间:2023-12-01 04:16:56 24 4
gpt4 key购买 nike

我是 Android 新手。我正在为我的项目构建一个绘图应用程序,我想知道你们是否可以就我的问题提供建议。这是我的代码。

paintclass.java

public class paintclass extends View {
//InputStream is = getResources().openRawResource(R.drawable.pic);

private static final float TOUCH_TOLERANCE = 4;
static Paint paint;
static Path path = new Path();
//private Paint cpaint;
//private Path cpath = new Path();
static int[] color = {255, 0, 0, 0};
static int[] stroke = {5, 20};
static boolean eraser = false;
public LayoutParams params;
Bitmap bitmap;
LinearLayout parentLinearLayout;
LinearLayout parentLinearLayout2;
LinearLayout ll;
private Canvas mcanvas;
private float mX, mY;

public paintclass(Context context) {
super(context);

bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
mcanvas = new Canvas(bitmap);
}

public paintclass(Context context, AttributeSet a) {
super(context, a);
bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
mcanvas = new Canvas(bitmap);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint = new Paint();
paint.setColor(Color.RED);
paint.setAntiAlias(true);
paint.setARGB(color[0], color[1], color[2], color[3]);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
if (eraser == true) {
paint.setStrokeWidth(stroke[1]);
} else {
paint.setStrokeWidth(stroke[0]);
}

paint.setDither(true);
paint.setStrokeCap(Paint.Cap.ROUND);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(bitmap, 0, 0, paint);
canvas.drawPath(path, paint);

invalidate();
}

private void touch_start(float x, float y) {
path.reset();
path.moveTo(x, y);
mX = x;
mY = y;
}

private void touch_move(float x, float y) {

float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
path.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
}
}

private void touch_up() {
path.lineTo(mX, mY);
mcanvas.drawPath(path, paint);
path.reset();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
// super.onTouchEvent(event);

float a = event.getX();
float b = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(a, b);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(a, b);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}
}

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/liner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffcc"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff9900"
android:orientation="horizontal">

<ImageView
android:id="@+id/prima"
android:layout_width="47dp"
android:layout_height="47dp"
android:src="@drawable/pic" />

<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="44dp"
android:layout_marginLeft="10dp"
android:singleLine="false"
android:text="Temporary text"
android:textAppearance="?android:attr/textAppearanceSearchResultTitle"
android:textSize="13sp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffcc"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp">

<ImageButton
android:id="@+id/bl"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/bl" />

<ImageButton
android:id="@+id/r"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/r" />

<ImageButton
android:id="@+id/b"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/b" />

<ImageButton
android:id="@+id/y"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/y" />

<ImageButton
android:id="@+id/o"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/o" />

<ImageButton
android:id="@+id/g"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/g" />

<ImageButton
android:id="@+id/p"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/p" />

<ImageButton
android:id="@+id/ad"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/ad" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:background="#cccccc"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">

<LinearLayout
android:id="@+id/drawingAre"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">

<com.depictry.paintclass xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/draw"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/addsize"
style="?android:attr/buttonStyleInset"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="+" />

<Button
android:id="@+id/minussize"
style="?android:attr/buttonStyleInset"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="-" />

<Button
android:id="@+id/clear"
style="?android:attr/buttonStyleInset"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="5dp"
android:layout_weight="0.10"
android:text="Clear" />

<Button
android:id="@+id/saveimage"
style="?android:attr/buttonStyleInset"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="5dp"
android:layout_weight="0.08"
android:text="Send" />
</LinearLayout>
</LinearLayout>

主要 Activity

but[i] = (Button) findViewById(R.id.saveimage);
but[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout ll = (LinearLayout) findViewById(R.id.drawingAre);
ImageView im = (ImageView) findViewById(R.id.prima);

ll.setDrawingCacheEnabled(true);
ll.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(ll.getDrawingCache());
ll.setDrawingCacheEnabled(false);
im.setImageBitmap(b);
}
});

这里的代码是我希望将图像上传到服务器文件夹的位置,但它所做的只是显示图像。有人可以帮忙吗?

最佳答案

是的,您可以将图像上传到服务器内的文件夹。
This答案可以帮助你。
它的 uploadToServer 类对您很有用,只需使用服务器上文件夹的路径即可。

关于java - Android:是否可以将图像上传到服务器内的文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19345333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com