آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

ساخت نرم افزار نقاشی و ذخیره نقاشی در حافظه دستگاه

صادی  8 سال پیش  8 سال پیش
0 0

سلام خدمت تمامی دوستان 

من یه نرم افزار نقاشی درست کردم ( با کمک ویدیو های آموزشی )
اما حالا میخوام همین نقاشی ذخیره کنم نمیشه 
این سورسی که برای ذخیره نرم افزار گرفتم به خوبی برای خودش کار میکنه اما تو سورس من نه 
کسی از دوستان میتونه راهنمایی کنه ؟

private File takeScreenshot(boolean showToast) {
View v = getWindow().getDecorView();
v.setDrawingCacheEnabled(true);
Bitmap cachedBitmap = v.getDrawingCache();
Bitmap copyBitmap = cachedBitmap.copy(Bitmap.Config.RGB_565, true);
FileOutputStream output = null;
File file = null;
try {
File path = Places.getScreenshotFolder();
Calendar cal = Calendar.getInstance();

file = new File(path,cal.get(Calendar.YEAR) + "_" + (1 + cal.get(Calendar.MONTH)) + "_"
+ cal.get(Calendar.DAY_OF_MONTH) + "_"
+ cal.get(Calendar.HOUR_OF_DAY) + "_"
+ cal.get(Calendar.MINUTE) + "_" + cal.get(Calendar.SECOND)
+ ".png");
output = new FileOutputStream(file);
copyBitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
}
catch (FileNotFoundException e) {
file = null;
e.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
}
catch (IOException e) {
e.printStackTrace();
}
}

}

if (file != null) {
if (showToast)
Toast.makeText(getApplicationContext(),
"ذخیره شد در مسیر " + file.getAbsolutePath(),
Toast.LENGTH_LONG).show();
// sending a broadcast to the media scanner so it will scan the new
// screenshot.
Intent requestScan = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
requestScan.setData(Uri.fromFile(file));
sendBroadcast(requestScan);

return file;
} else {
return null;
}
}

این متودی که برای ذخیره استفاده میشه 

و این 


public class Places {
public static File getScreenshotFolder() {
File path = new File(Environment.getExternalStorageDirectory(),
"/Acrylic Paint/");
path.mkdirs();

return path;
}

public static File getCameraTempFolder() {
File path = new File(Environment.getExternalStorageDirectory(),
"/Acrylic Paint/Temp/");
path.mkdirs();
// this folder should not be scanned
File noScanning = new File(path, ".nomedia");
if (!noScanning.exists())
try {
noScanning.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return path;
}

public static File getCameraTempFile() {
return new File(getCameraTempFolder(), "temp.jpg");
}
}

کلاسیه که اون متود ازش برای ذخیره استفاده میکنه

و این هم کلاسیه که من برای نقاشی کشیدن ازش استفاده میکنم 

public class SingleTouchView extends View {

public Context context = SingleTouchView.this.getContext() ;
public int BRUSH_SIZE = 10 ;
public static final int DEFAULT_COLOR = Color.RED ;
public static final int DEFAULT_BG_COLOR = Color.WHITE ;
private static final float TOUCH_TOLERANCE = 4 ;
private float mX , mY ;
private Path mPath ;
private Paint mPaint ;
private ArrayList<FingerPath> paths = new ArrayList<>();
private int currentColor ;
private int backgroundColor = DEFAULT_BG_COLOR ;
private int strokeWidth ;
// private boolean emboss ;
// private boolean blur ;
private MaskFilter mEmboss ;
private MaskFilter mBlur ;
public Matrix matrix ;
private Bitmap mBitmap ;
private Canvas mCanvas ;
private Paint mBitmapPaint = new Paint(Paint.DITHER_FLAG);

public SingleTouchView(Context context) {
this(context , null);
}

public SingleTouchView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(DEFAULT_COLOR);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setXfermode(null);
mPaint.setAlpha(0xFF);

// mEmboss = new EmbossMaskFilter(new float[] {1,1,1} , 0.4f , 6 , 3.5f);
// mBlur = new BlurMaskFilter(5,BlurMaskFilter.Blur.NORMAL);
}

public void init(DisplayMetrics metrics , String color , int BRUSH_SIZE){
int height = metrics.heightPixels;
int width = metrics.widthPixels;

mBitmap = Bitmap.createBitmap(width , height , Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);

currentColor = Color.parseColor("#"+color) ;
strokeWidth = BRUSH_SIZE ;
}

public Bitmap getBitmap(){
this.setDrawingCacheEnabled(true);
this.buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(this.getDrawingCache());
this.setDrawingCacheEnabled(false);
return bmp;
}

// public void normal (){
// emboss = false ;
// blur = false ;
// }
//
// public void emboss (){
// emboss = true ;
// blur = false ;
// }
//
// public void blur (){
// emboss = false ;
// blur = true ;
// }

public void backgroundColor (int color){
backgroundColor = color ;
invalidate();
}

public void clear(int color){
backgroundColor = color ;
paths.clear();
// normal();
invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
canvas.save();
mCanvas.drawColor(backgroundColor);

for (FingerPath fp : paths){
mPaint.setColor(fp.color);
mPaint.setStrokeWidth(fp.strokeWidth);
mPaint.setMaskFilter(null);

// if (fp.emboss)
// mPaint.setMaskFilter(mEmboss);
// else if (fp.blur)
// mPaint.setMaskFilter(mBlur);

mCanvas.drawPath(fp.path , mPaint);
}
canvas.drawBitmap(mBitmap , 0 , 0 , mBitmapPaint);
canvas.restore();
}

private void touchStart (float x, float y){
mPath = new Path();
FingerPath fp = new FingerPath(currentColor , strokeWidth ,mPath);
paths.add(fp);

mPath.reset();
mPath.moveTo(x,y);
mX = x ;
mY = y ;
}

private void touchMove(float x, float y){
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);

if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE){
mPath.quadTo(mX , mY , (x + mX) / 2 , (y + mY) / 2);
mX = x ;
mY = y ;
}
}

private void touchUp (){
mPath.lineTo(mX , mY);
}

@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()){
case MotionEvent.ACTION_DOWN :
touchStart(x , y);
invalidate();
break;
case MotionEvent.ACTION_MOVE :
touchMove(x , y);
invalidate();
break;
case MotionEvent.ACTION_UP :
touchUp();
invalidate();
break;
}

return true ;
}
}


ممنون میشم راهنمایی کنید چند روزه درگیرم و میدونم مشکل از داخل کد هست چون تمامی سایتا رو گشتم و چیزی جدید پیدا نکردم 
همه یه چیز میگن و من نمیدونم چطوری باید اجرا کنمش

 

با تشکر

0 0
پرمیشن رو در منیفست وارد کردید ؟اگر اندروید شیش به بالا باشه باید دسترسی رو در هنگام استفاده از برنامه از کاربر بگیرید ( رانتایم پرمیشن *) (8 سال پیش)
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .