handled this by saving the image to the ContentProvider
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI and then
saving the created URI to the database along with my item. An example
of how to do this can be found here:
-
-
packagecom.google.android.photostream;
-
importandroid.app.Activity;
-
importandroid.content.Context;
-
importandroid.content.Intent;
-
importandroid.content.ActivityNotFoundException;
-
importandroid.os.Bundle;
-
importandroid.widget.TextView;
-
importandroid.widget.ImageView;
-
importandroid.widget.ViewAnimator;
-
importandroid.widget.LinearLayout;
-
importandroid.widget.Toast;
-
importandroid.graphics.Bitmap;
-
importandroid.graphics.BitmapFactory;
-
importandroid.graphics.drawable.Drawable;
-
importandroid.graphics.drawable.BitmapDrawable;
-
importandroid.view.View;
-
importandroid.view.ViewGroup;
-
importandroid.view.ViewTreeObserver;
-
importandroid.view.Menu;
-
importandroid.view.MenuItem;
-
importandroid.view.animation.AnimationUtils;
-
importandroid.net.Uri;
-
importjava.io.File;
-
importjava.io.IOException;
-
importjava.io.OutputStream;
-
importjava.io.InputStream;
-
importjava.io.FileNotFoundException;
-
-
-
publicclassViewPhotoActivityextendsActivityimplementsView.OnClickListener,
- ViewTreeObserver.OnGlobalLayoutListener{
-
staticfinalStringACTION="com.google.android.photostream.FLICKR_PHOTO";
-
privatestaticfinalStringRADAR_ACTION="com.google.android.radar.SHOW_RADAR";
-
privatestaticfinalStringRADAR_EXTRA_LATITUDE="latitude";
-
privatestaticfinalStringRADAR_EXTRA_LONGITUDE="longitude";
-
privatestaticfinalStringEXTRA_PHOTO="com.google.android.photostream.photo";
-
privatestaticfinalStringWALLPAPER_FILE_NAME="wallpaper";
-
privatestaticfinalintREQUEST_CROP_IMAGE=42;
-
privateFlickr.PhotomPhoto;
-
privateViewAnimatormSwitcher;
-
privateImageViewmPhotoView;
-
privateViewGroupmContainer;
-
privateUserTask<?,?,?>mTask;
-
privateTextViewmPhotoTitle;
-
privateTextViewmPhotoDate;
-
@Override
-
protectedvoidonCreate(BundlesavedInstanceState){
-
super.onCreate(savedInstanceState);
- mPhoto=getPhoto();
- setContentView(R.layout.screen_photo);
- setupViews();
- }
-
-
-
staticvoidshow(Contextcontext,Flickr.Photophoto){
-
finalIntentintent=newIntent(context,ViewPhotoActivity.class);
- intent.putExtra(EXTRA_PHOTO,photo);
- context.startActivity(intent);
- }
-
@Override
-
protectedvoidonDestroy(){
-
super.onDestroy();
-
if(mTask!=null&&mTask.getStatus()!=UserTask.Status.RUNNING){
-
mTask.cancel(true);
- }
- }
-
privatevoidsetupViews(){
- mContainer=(ViewGroup)findViewById(R.id.container_photo);
- mSwitcher=(ViewAnimator)findViewById(R.id.switcher_menu);
- mPhotoView=(ImageView)findViewById(R.id.image_photo);
- mPhotoTitle=(TextView)findViewById(R.id.caption_title);
- mPhotoDate=(TextView)findViewById(R.id.caption_date);
-
findViewById(R.id.menu_back).setOnClickListener(this);
-
findViewById(R.id.menu_set).setOnClickListener(this);
- mPhotoTitle.setText(mPhoto.getTitle());
- mPhotoDate.setText(mPhoto.getDate());
- mContainer.setVisibility(View.INVISIBLE);
-
-
-
-
mContainer.getViewTreeObserver().addOnGlobalLayoutListener(this);
- }
-
-
-
publicvoidonGlobalLayout(){
-
mContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
- loadPhoto(mPhotoView.getMeasuredWidth(),mPhotoView.getMeasuredHeight());
- }
-
-
-
privatevoidloadPhoto(intwidth,intheight){
-
finalObjectdata=getLastNonConfigurationInstance();
-
if(data==null){
-
mTask=newLoadPhotoTask().execute(mPhoto,width,height);
-
}else{
- mPhotoView.setImageBitmap((Bitmap)data);
- mSwitcher.showNext();
- }
- }
-
-
-
publicFlickr.PhotogetPhoto(){
-
finalIntentintent=getIntent();
-
finalBundleextras=intent.getExtras();
-
Flickr.Photophoto=null;
-
if(extras!=null){
- photo=extras.getParcelable(EXTRA_PHOTO);
- }
-
returnphoto;
- }
-
@Override
-
publicbooleanonCreateOptionsMenu(Menumenu){
- getMenuInflater().inflate(R.menu.view_photo,menu);
-
returnsuper.onCreateOptionsMenu(menu);
- }
-
@Override
-
publicbooleanonMenuItemSelected(intfeatureId,MenuItemitem){
-
switch(item.getItemId()){
-
caseR.id.menu_item_radar:
- onShowRadar();
-
break;
- }
-
returnsuper.onMenuItemSelected(featureId,item);
- }
-
privatevoidonShowRadar(){
-
newShowRadarTask().execute(mPhoto);
- }
-
publicvoidonClick(Viewv){
-
switch(v.getId()){
-
caseR.id.menu_back:
- onBack();
-
break;
-
caseR.id.menu_set:
- onSet();
-
break;
- }
- }
-
privatevoidonSet(){
-
mTask=newCropWallpaperTask().execute(mPhoto);
- }
-
privatevoidonBack(){
- finish();
- }
-
-
-
@Override
-
publicObjectonRetainNonConfigurationInstance(){
-
finalDrawabled=mPhotoView.getDrawable();
-
returnd!=null?((BitmapDrawable)d).getBitmap():null;
- }
-
@Override
-
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
-
-
-
if(requestCode==REQUEST_CROP_IMAGE){
-
if(resultCode==RESULT_OK){
-
mTask=newSetWallpaperTask().execute();
-
}else{
- cleanupWallpaper();
- showWallpaperError();
- }
- }
- }
-
privatevoidshowWallpaperError(){
-
Toast.makeText(ViewPhotoActivity.this,R.string.error_cannot_save_file,
- Toast.LENGTH_SHORT).show();
- }
-
privatevoidshowWallpaperSuccess(){
-
Toast.makeText(ViewPhotoActivity.this,R.string.success_wallpaper_set,
- Toast.LENGTH_SHORT).show();
- }
-
privatevoidcleanupWallpaper(){
- deleteFile(WALLPAPER_FILE_NAME);
- mSwitcher.showNext();
- }
-
-
-
privateclassLoadPhotoTaskextendsUserTask<Object,Void,Bitmap>{
-
publicBitmapdoInBackground(Object...params){
-
Bitmapbitmap=((Flickr.Photo)params[0]).loadPhotoBitmap(Flickr.PhotoSize.MEDIUM);
-
if(bitmap==null){
- bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.not_found);
- }
-
finalintwidth=(Integer)params[1];
-
finalintheight=(Integer)params[2];
-
finalBitmapframed=ImageUtilities.scaleAndFrame(bitmap,width,height);
- bitmap.recycle();
-
returnframed;
- }
-
@Override
-
publicvoidonPostExecute(Bitmapresult){
- mPhotoView.setImageBitmap(result);
-
-
-
finalintoffsetX=(mPhotoView.getMeasuredWidth()-result.getWidth())/2;
-
-
-
- LinearLayout.LayoutParamsparams;
- params=(LinearLayout.LayoutParams)mPhotoView.getLayoutParams();
- params.height=result.getHeight();
-
params.weight=0.0f;
- mPhotoView.setLayoutParams(params);
- params=(LinearLayout.LayoutParams)mPhotoTitle.getLayoutParams();
- params.leftMargin=offsetX;
- mPhotoTitle.setLayoutParams(params);
- params=(LinearLayout.LayoutParams)mPhotoDate.getLayoutParams();
- params.leftMargin=offsetX;
- mPhotoDate.setLayoutParams(params);
- mSwitcher.showNext();
-
mContainer.startAnimation(AnimationUtils.loadAnimation(ViewPhotoActivity.this,
- R.anim.fade_in));
- mContainer.setVisibility(View.VISIBLE);
-
mTask=null;
- }
- }
-
-
-
privateclassCropWallpaperTaskextendsUserTask<Flickr.Photo,Void,Boolean>{
-
privateFilemFile;
-
@Override
-
publicvoidonPreExecute(){
- mFile=getFileStreamPath(WALLPAPER_FILE_NAME);
- mSwitcher.showNext();
- }
-
publicBooleandoInBackground(Flickr.Photo...params){
-
booleansuccess=false;
-
OutputStreamout=null;
-
try{
- out=openFileOutput(mFile.getName(),MODE_WORLD_READABLE|MODE_WORLD_WRITEABLE);
-
Flickr.get().downloadPhoto(params[0],Flickr.PhotoSize.LARGE,out);
-
success=true;
-
}catch(FileNotFoundExceptione){
-
android.util.Log.e(Flickr.LOG_TAG,"Couldnotdownloadphoto",e);
-
success=false;
-
}catch(IOExceptione){
-
android.util.Log.e(Flickr.LOG_TAG,"Couldnotdownloadphoto",e);
-
success=false;
-
}finally{
-
if(out!=null){
-
try{
- out.close();
-
}catch(IOExceptione){
-
success=false;
- }
- }
- }
-
returnsuccess;
- }
-
@Override
-
publicvoidonPostExecute(Booleanresult){
-
if(!result){
- cleanupWallpaper();
- showWallpaperError();
-
}else{
-
finalintwidth=getWallpaperDesiredMinimumWidth();
-
finalintheight=getWallpaperDesiredMinimumHeight();
-
finalIntentintent=newIntent("com.android.camera.action.CROP");
-
intent.setClassName("com.android.camera","com.android.camera.CropImage");
- intent.setData(Uri.fromFile(mFile));
-
intent.putExtra("outputX",width);
-
intent.putExtra("outputY",height);
-
intent.putExtra("aspectX",width);
-
intent.putExtra("aspectY",height);
-
intent.putExtra("scale",true);
-
intent.putExtra("noFaceDetection",true);
-
intent.putExtra("output",Uri.parse("file:/"+mFile.getAbsolutePath()));
- startActivityForResult(intent,REQUEST_CROP_IMAGE);
- }
-
mTask=null;
- }
- }
-
-
-
privateclassSetWallpaperTaskextendsUserTask<Void,Void,Boolean>{
-
publicBooleandoInBackground(Void...params){
-
booleansuccess=false;
-
InputStreamin=null;
-
try{
- in=openFileInput(WALLPAPER_FILE_NAME);
- setWallpaper(in);
-
success=true;
-
}catch(IOExceptione){
-
success=false;
-
}finally{
-
if(in!=null){
-
try{
- in.close();
-
}catch(IOExceptione){
-
success=false;
- }
- }
- }
-
returnsuccess;
- }
-
@Override
-
publicvoidonPostExecute(Booleanresult){
- cleanupWallpaper();
-
if(!result){
- showWallpaperError();
-
}else{
- showWallpaperSuccess();
- }
-
mTask=null;
- }
- }
-
privateclassShowRadarTaskextendsUserTask<Flickr.Photo,Void,Flickr.Location>{
-
publicFlickr.LocationdoInBackground(Flickr.Photo...params){
-
returnFlickr.get().getLocation(params[0]);
- }
-
@Override
-
publicvoidonPostExecute(Flickr.Locationlocation){
-
if(location!=null){
-
finalIntentintent=newIntent(RADAR_ACTION);
- intent.putExtra(RADAR_EXTRA_LATITUDE,location.getLatitude());
- intent.putExtra(RADAR_EXTRA_LONGITUDE,location.getLongitude());
-
try{
- startActivity(intent);
-
}catch(ActivityNotFoundExceptione){
-
Toast.makeText(ViewPhotoActivity.this,R.string.error_cannot_find_radar,
- Toast.LENGTH_SHORT).show();
- }
-
}else{
-
Toast.makeText(ViewPhotoActivity.this,R.string.error_cannot_find_location,
- Toast.LENGTH_SHORT).show();
- }
- }
- }
- }
分享到:
相关推荐
本文将深入探讨如何在数据库中管理图像数据,主要基于标题和描述中的关键词,如"database_image"、"sql_save_image_pudn"、"sql_图片"、"sql__image"和"sql_image_读取"。 首先,我们来讨论如何在SQL数据库中存储...
标题"SaveImage_c#mysql数据库上传图片_more11h_MYSQL_savelmage_SAVe:IMAGe_"暗示我们将探讨一个C#应用程序,它能够将图像数据存储到MySQL数据库中。描述提到"连接mysql数据库,并且读取,保存图片的方法",意味着...
这可以通过`Image.Save`方法实现,提供一个`MemoryStream`,并指定适当的图像格式(如JPEG或PNG)。 - 创建`SqlCommand`,设置SQL插入语句,如:`INSERT INTO TableName (ImageField) VALUES (@ImageData)`。 - ...
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imageData = memoryStream.ToArray(); string query = "INSERT INTO TableName (ImageColumn) VALUES (@ImageData)"; SqlCommand ...
In-place image and BLOB viewing Selected rows deletion Jump to specific record Built-in table Print Preview and Print Table Customization Table customization available for each table separately ...
image.Save(ms, image.RawFormat); byte[] imageData = ms.ToArray(); // 创建数据库连接 string connectionString = "Your Connection String"; using (SqlConnection connection = new SqlConnection...
Modify table structure visually without losing data already existing in the database. SQLite Expert will automatically create a new table with the new structure and copy the data from the old table. ...
1. Modify table structure visually without losing data already existing in the database. SQLite Expert will automatically create a new table with the new structure and copy the data from the old table...
1. Modify table structure visually without losing data already existing in the database. SQLite Expert will automatically create a new table with the new structure and copy the data from the old table...
// Save a TBitMap image to a ZIP archive. // Create and initialize a bitmap image. Img := TBitMap.Create; // Add a new entry to the ZIP archive. DIZipWriter.AddEntry('MyImage'); // Write the ...
Added: support of cross-database hyperlinks, which allows to make hyperlinks to info items saved in different .nyf databases; It's required to first have target databases open before making cross-db ...
pictureBox2.Image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imageByte = imageStream.GetBuffer(); MySqlConnection conn = new MySqlConnection("Server=localhost;Uid=root;...
save and restore columns order and display width in ini-files and system registry; display icons for BLOB, memo, OLE and picture fields; select multiple records; convert columns headings to buttons. ...
image.save("output.png", "PNG")) { // 处理保存失败的情况 } ``` 在保存图像到数据库之前,我们需要将图像转换为适合数据库存储的格式。通常,这涉及到将图像数据编码为字符串或二进制流。QT提供`QByteArray`类...
MySQL, a popular open-source relational database management system, is utilized for storing and managing data related to flowers, orders, users, and other essential entities in the system. It ensures ...
You can compare program units, tables, views, sequences with sources in the database, in a file or in a window. A new Oracle / Options preference "Always include owner prefix" has been added. When ...
You can compare program units, tables, views, sequences with sources in the database, in a file or in a window. A new Oracle / Options preference "Always include owner prefix" has been added. When ...
You can compare program units, tables, views, sequences with sources in the database, in a file or in a window. A new Oracle / Options preference "Always include owner prefix" has been added. When ...
You can compare program units, tables, views, sequences with sources in the database, in a file or in a window. A new Oracle / Options preference "Always include owner prefix" has been added. When ...
File Save and Save As File Open Print Font Browser Color Chooser Summary Chapter 6: User Interface Issues Developing Applications The Problems with Application Development The MFC Solution ...