小编ya *_*Lya的帖子

如何使用multipart-form数据json将图像(位图)发送到android中的服务器

我有代码将图像上传到服务器,它的工作原理,

HttpEntity resEntity;

                HttpClient httpClient = new DefaultHttpClient();
                HttpPost post = new HttpPost(Constants.url_create_product);
                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                File file= new File(path);
                FileBody bin = new FileBody(file);

                reqEntity.addPart("phone", new StringBody(mPhoneNumber));
                reqEntity.addPart("prod_title", new StringBody(namapro));
                reqEntity.addPart("prod_price", new StringBody(hargapro));
                reqEntity.addPart("prod_desc", new StringBody(despro));
                reqEntity.addPart("prod_order", new StringBody(orderpro));
                reqEntity.addPart("prod_image", bin);

                post.setEntity(reqEntity);
                    HttpResponse response = httpClient.execute(post);
                resEntity = response.getEntity();
                String response_str = EntityUtils.toString(resEntity);
                Gson gson = new Gson(); 
                gson.toJson(response_str);
                 if (resEntity != null) {
                     Log.i("RESPONSE",response_str);
                     runOnUiThread(new Runnable(){
                            public void run() {
                                 try {
                                    Toast.makeText(getApplicationContext(),"Upload Complete. Check the …
Run Code Online (Sandbox Code Playgroud)

android

12
推荐指数
2
解决办法
5万
查看次数

在android中添加水印图像

我有代码在这样的图像中添加水印

public static Bitmap mark(Bitmap src, String watermark, Point location, Color color, int alpha, int size, boolean underline) {
            int w = src.getWidth();
            int h = src.getHeight();
            Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());

            Canvas canvas = new Canvas(result);
            canvas.drawBitmap(src, 0, 0, null);

            Paint paint = new Paint();
            paint.setColor(color.RED);
            paint.setAlpha(alpha);
            paint.setTextSize(size);
            paint.setAntiAlias(true);
            paint.setUnderlineText(underline);
            canvas.drawText(watermark, location.x, location.y, paint);

            return result;
        }
Run Code Online (Sandbox Code Playgroud)

我用这段代码调用该函数

mark(bitmap, "watermark", b, null, c, 100, false);
            imgshoot.setImageBitmap(bitmap);
Run Code Online (Sandbox Code Playgroud)

但什么都没发生,你可以帮助我?谢谢

android android-layout

5
推荐指数
1
解决办法
8832
查看次数

标签 统计

android ×2

android-layout ×1