我已将图像存储为类型-image-在我的数据库(Sqlserver)中问题是当我尝试将其发送到android作为类型byte []我有内存错误因为我尝试尝试加载所有图像同时 ... 我在这里找到的解决方案之一是将图像作为链接发送,只有想象才需要它 现在我想只获取php中的图像链接并将其发送到android 我不知道如何将图像(存储在DB中)转换为php中的链接并将其发送到android
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.MyTag>{
LayoutInflater inflater;
DbConnection db ;
CnxExternal myConex = new CnxExternal();
ArrayList<Map<String, String>> listitem;
private CardAdapter.MyTag holder;
Context ctx;
ArrayList<byte[]> img , imgfou ;
ArrayList<String>nomesFo,descriptions;
String codeBar;
ArrayList<Integer>idfourns;
public CardAdapter(Context context, ArrayList<Map<String, String>> list,ArrayList<byte[]>imagbyt,ArrayList<String>names,ArrayList<Integer>idf,String cod,ArrayList<String>Description,ArrayList<byte[]>imagfour) {
super();
this.inflater = LayoutInflater.from(context);
this.listitem = list;
ctx=context;
this.img=imagbyt;
this.nomesFo=names;
this.idfourns=idf;
this.codeBar=cod;
this.imgfou=imagfour;
this.descriptions=Description;
db =new DbConnection(ctx);
}
public class MyTag extends RecyclerView.ViewHolder {
TextView price;
TextView name;
ImageView img;
TextView namfou;
TextView rating;
FloatingActionButton btnlike;
CardView cardView;
public MyTag(View view) {
super(view);
//for animat
cardView=(CardView)view.findViewById(R.id.card_view);
price = (TextView) view.findViewById(R.id.prixprodtestcard);
name = (TextView) view.findViewById(R.id.nomprodtestcard);
namfou=(TextView) view.findViewById(R.id.qtestockcard);
rating=(TextView)view.findViewById(R.id.rating);
img = (ImageView) view.findViewById(R.id.imageprodcard);
btnlike = (FloatingActionButton) view.findViewById(R.id.likeButtoncard);
}
}
@Override
public MyTag onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, null);
return new MyTag(v);
}
@Override
public int getItemCount() {
return listitem.size();
}
@Override
public void onViewRecycled(MyTag holder) {
super.onViewRecycled(holder);
Glide.clear(holder.img);
}
public void onBindViewHolder(final MyTag holder, final int position) {
//anim fadein
YoYo.with(Techniques.SlideInUp)
.playOn(holder.cardView);
final HashMap<String, String> map = (HashMap<String, String>)listitem.get(position);
if(map.get("like").equals("0")){
holder.btnlike.setImageResource(R.drawable.heart);
}else{
holder.btnlike.setImageResource(R.drawable.ic_liked);
}
holder.img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ctx,InformationsProduit.class);
i.putExtra("nomProd",map.get("name"));
i.putExtra("prix",map.get("price"));
i.putExtra("nomFour",nomesFo.get(position));
i.putExtra("image",img.get(position));
i.putExtra("telFour",map.get("telefournisseur"));
i.putExtra("addrFour",map.get("adressFou"));
i.putExtra("idFour",idfourns.get(position));
i.putExtra("description",descriptions.get(position));
i.putExtra("codeBar",codeBar);
ctx.startActivity(i);
}
});
holder.price.setText(map.get("price"));
holder.name.setText(map.get("name"));
holder.namfou.setText(nomesFo.get(position));
holder.rating.setText(map.get("rating"));
Glide.with(ctx)
.load(imgfou.get(position))
//.diskCacheStrategy( DiskCacheStrategy.NONE )
//.skipMemoryCache( true )
.thumbnail(0.1f)
.into(holder.img);
holder.btnlike.setOnClickListener(new View.OnClickListener() {
CardAdapter.MyTag hld=holder;
int pos=position;
@Override
public void onClick(View arg0) {
HashMap<String, String> mapclicked = (HashMap<String, String>)listitem.get(pos);
if(mapclicked.get("like").equals("0"))
{
hld.btnlike.setImageResource(R.drawable.ic_liked);
mapclicked.put("like", "1");
Snackbar snackbar;
snackbar = Snackbar.make(hld.btnlike, "Bien ajouter au prefere", Snackbar.LENGTH_SHORT);
View snackBarView = snackbar.getView();
snackBarView.setBackgroundColor(Color.GREEN);
TextView textView = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.WHITE);
snackbar.show();
db.insertFav(codeBar,idfourns.get(pos) , map.get("name") , map.get("price") , nomesFo.get(position) , map.get("adressFou") , map.get("telefournisseur") ,img.get(position) );
hld.btnlike.startAnimation(animAdp());
}else{
hld.btnlike.setImageResource(R.drawable.heart);
mapclicked.put("like", "0");
Snackbar.make(hld.btnlike, "Removed from prefere" , Snackbar.LENGTH_LONG).setAction("Action", null).show();
db.deleteR(codeBar,idfourns.get(pos));
hld.btnlike.startAnimation(animAdp());
}
}}
);
}
答案 0 :(得分:0)
你内存不足,因为你试图将所有图像都放在同一个文件中Json
试试这个解决方案:
Glide.with(ctx)
.load("http://192.168.1.8/connect/getimage.php")
.into(holder.img);
脚本PHP ==&gt; getimage.php
$sql="select img from table where id=1032 ";
$stmt = sqlsrv_prepare( $this->connection, $sql);
$result = sqlsrv_execute($stmt);
$information = array();
while($data = sqlsrv_fetch_array($stmt))
{
$img=$data['img'];
}
echo $img;